-
Notifications
You must be signed in to change notification settings - Fork 4
/
log.ts
40 lines (33 loc) · 1.24 KB
/
log.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Logger } from 'pino'
import { app } from 'electron'
import { createWriteStream } from 'fs'
const pinoms = require('pino-multi-stream')
export const initLogger = (isDev = false) => {
app.setAppLogsPath()
const logBasePath = app.getPath('logs')
const fileOutStream = (title: string) => createWriteStream(`${logBasePath}/${app.name}.${title}.log`, { flags: 'a' })
const devlogs = isDev ? [
{ level: 'trace', stream: pinoms.prettyStream() },
{ level: 'trace', stream: fileOutStream('trace') }
] : []
const lg: Logger = pinoms({
streams: [
...devlogs,
{ level: 'info', stream: fileOutStream('info') },
{ level: 'warn', stream: fileOutStream('warn') },
{ level: 'error', stream: fileOutStream('error') },
{ level: 'fatal', stream: fileOutStream('fatal') }
]
}) as Logger
const master = lg.child({ ver: app.getVersion() })
const main = master.child({ platform: 'electron-main' })
const rdr = master.child({ platform: 'electron-renderer' })
const thisLogger = main.child({ ns: 'initLogger()' })
thisLogger.info('Logging Started!')
thisLogger.info(`Logs storage directory set to: ${logBasePath}`)
thisLogger.info('Development logging enabled:', isDev)
return {
main,
rdr
}
}