From c2f6330daf3d84d8b5a11b1170025c6961554569 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 22 Mar 2024 12:34:44 +0700 Subject: [PATCH] chore: log system information for debugging (#2453) --- electron/main.ts | 5 ++- electron/utils/system.ts | 16 ++++++++++ .../monitoring-extension/src/node/index.ts | 2 +- web/containers/ModalTroubleShoot/AppLogs.tsx | 2 +- .../ModalTroubleShoot/DeviceSpecs.tsx | 32 ++++++++++++++++--- web/containers/ServerLogs/index.tsx | 2 +- web/hooks/useLogs.tsx | 2 +- 7 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 electron/utils/system.ts diff --git a/electron/main.ts b/electron/main.ts index 70314b169..5e1ad6843 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -28,6 +28,7 @@ import { cleanLogs } from './utils/log' import { registerShortcut } from './utils/selectedText' import { trayManager } from './managers/tray' +import { logSystemInfo } from './utils/system' const preloadPath = join(__dirname, 'preload.js') const rendererPath = join(__dirname, '..', 'renderer') @@ -65,9 +66,7 @@ app } }) .then(() => process.env.CI !== 'e2e' && trayManager.createSystemTray()) - .then(() => { - log(`Version: ${app.getVersion()}`) - }) + .then(logSystemInfo) .then(() => { app.on('activate', () => { if (!BrowserWindow.getAllWindows().length) { diff --git a/electron/utils/system.ts b/electron/utils/system.ts new file mode 100644 index 000000000..5799de861 --- /dev/null +++ b/electron/utils/system.ts @@ -0,0 +1,16 @@ +import { log } from '@janhq/core/node' +import { app } from 'electron' +import os from 'os' + +export const logSystemInfo = (): void => { + log(`[SPECS]::Version: ${app.getVersion()}`) + log(`[SPECS]::CPUs: ${JSON.stringify(os.cpus())}`) + log(`[SPECS]::Machine: ${os.machine()}`) + log(`[SPECS]::Endianness: ${os.endianness()}`) + log(`[SPECS]::Parallelism: ${os.availableParallelism()}`) + log(`[SPECS]::Free Mem: ${os.freemem()}`) + log(`[SPECS]::Total Mem: ${os.totalmem()}`) + log(`[SPECS]::OS Version: ${os.version()}`) + log(`[SPECS]::OS Platform: ${os.platform()}`) + log(`[SPECS]::OS Release: ${os.release()}`) +} diff --git a/extensions/monitoring-extension/src/node/index.ts b/extensions/monitoring-extension/src/node/index.ts index 51fd0f070..17b56dbfd 100644 --- a/extensions/monitoring-extension/src/node/index.ts +++ b/extensions/monitoring-extension/src/node/index.ts @@ -232,7 +232,7 @@ const updateGpuInfo = async () => 'nvidia-smi --query-gpu=index,memory.total,name --format=csv,noheader,nounits', (error, stdout) => { if (!error) { - log(stdout) + log(`[SPECS]::${stdout}`) // Get GPU info and gpu has higher memory first let highestVram = 0 let highestVramId = '0' diff --git a/web/containers/ModalTroubleShoot/AppLogs.tsx b/web/containers/ModalTroubleShoot/AppLogs.tsx index d4f6bddb8..bd2dd2ceb 100644 --- a/web/containers/ModalTroubleShoot/AppLogs.tsx +++ b/web/containers/ModalTroubleShoot/AppLogs.tsx @@ -9,7 +9,7 @@ import { useLogs } from '@/hooks/useLogs' const AppLogs = () => { const { getLogs } = useLogs() - const [logs, setLogs] = useState([]) + const [logs, setLogs] = useState([]) useEffect(() => { getLogs('app').then((log) => { diff --git a/web/containers/ModalTroubleShoot/DeviceSpecs.tsx b/web/containers/ModalTroubleShoot/DeviceSpecs.tsx index 5ebb610d1..a657ffd5d 100644 --- a/web/containers/ModalTroubleShoot/DeviceSpecs.tsx +++ b/web/containers/ModalTroubleShoot/DeviceSpecs.tsx @@ -1,14 +1,28 @@ -import React from 'react' +import React, { useEffect, useState } from 'react' import { Button } from '@janhq/uikit' import { CopyIcon, CheckIcon } from 'lucide-react' import { useClipboard } from '@/hooks/useClipboard' +import { useLogs } from '@/hooks/useLogs' // TODO @Louis help add missing information device specs const DeviceSpecs = () => { - const userAgent = window.navigator.userAgent + const { getLogs } = useLogs() + const [logs, setLogs] = useState([]) + + useEffect(() => { + getLogs('app').then((log) => { + if (typeof log?.split === 'function') { + setLogs( + log.split(/\r?\n|\r|\n/g).filter((e) => e.includes('[SPECS]::')) + ) + } + }) + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) const clipboard = useClipboard({ timeout: 1000 }) return ( @@ -18,7 +32,7 @@ const DeviceSpecs = () => { themes="outline" className="bg-white dark:bg-secondary/50" onClick={() => { - clipboard.copy(userAgent ?? '') + clipboard.copy(logs ?? '') }} >
@@ -37,7 +51,17 @@ const DeviceSpecs = () => {
-

{userAgent}

+
+ + {logs.map((log, i) => { + return ( +

+ {log} +

+ ) + })} +
+
) diff --git a/web/containers/ServerLogs/index.tsx b/web/containers/ServerLogs/index.tsx index a980fefff..a6d5a16c9 100644 --- a/web/containers/ServerLogs/index.tsx +++ b/web/containers/ServerLogs/index.tsx @@ -19,7 +19,7 @@ const ServerLogs = (props: ServerLogsProps) => { const { limit = 0 } = props const { getLogs } = useLogs() const serverEnabled = useAtomValue(serverEnabledAtom) - const [logs, setLogs] = useState([]) + const [logs, setLogs] = useState([]) const clipboard = useClipboard({ timeout: 1000 }) diff --git a/web/hooks/useLogs.tsx b/web/hooks/useLogs.tsx index 91620d6c3..73733fbb8 100644 --- a/web/hooks/useLogs.tsx +++ b/web/hooks/useLogs.tsx @@ -9,7 +9,7 @@ export const useLogs = () => { const janDataFolderPath = useAtomValue(janDataFolderPathAtom) const getLogs = useCallback( - async (file: string) => { + async (file: string): Promise => { const path = await joinPath(['file://logs', `${file}.log`]) if (!(await fs.existsSync(path))) return '' const logs = await fs.readFileSync(path, 'utf-8')