Skip to content

Commit

Permalink
feat: persistant logs (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau authored Jun 9, 2022
1 parent 5975b76 commit 0c5d67d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ Linux: `bee-desktop-0.4.0-1.x86_64.rpm` or `bee-desktop_0.4.0_amd64.deb`

> You can alternatively clone this repository and run `npm install` and then `npm start`
# Logs

If you run the build version you can access logs of Bee Desktop at:

- macOS: `~/Library/Logs/bee-desktop-nodejs/bee-desktop.log`
- Windows: `%LOCALAPPDATA%\bee-desktop-nodejs\Log\bee-desktop.log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log\bee-desktop.log`)
- Linux: `~/.local/state/bee-desktop-nodejs/bee-desktop.log`

# If you have a previous installation

You need to delete the previous assets first to receive updates
Expand Down
12 changes: 10 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import requestStats from 'request-stats'
import type { Server } from 'http'

import { SupportedLevels, SUPPORTED_LEVELS, logLevel } from './config'
import { getLogPath } from './path'

const supportedLevels: Record<SupportedLevels, number> = SUPPORTED_LEVELS.reduce(
(acc, cur, idx) => ({ ...acc, [cur]: idx }),
Expand All @@ -17,9 +18,16 @@ export const logger: Logger = createLogger({
format.metadata(),
format.timestamp(),
format.printf(formatLogMessage),
format.colorize({ all: true }),
),
transports: [new transports.Console({ level: logLevel })],
transports: [
new transports.Console({ level: logLevel, format: format.colorize({ all: true }) }),
new transports.File({
filename: getLogPath('bee-desktop.log'),
maxsize: 1_000_000,
maxFiles: 10,
tailable: true,
}),
],
})

logger.info(`using max log level=${logLevel}`)
Expand Down
4 changes: 4 additions & 0 deletions src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export function checkPath(path: string): boolean {
export function getPath(path: string): string {
return join(paths.data, path)
}

export function getLogPath(logFileName: string): string {
return join(paths.log, logFileName)
}

0 comments on commit 0c5d67d

Please sign in to comment.