Simple logger for Electron app based on Winston.
Tip
The default write location for log files via the Electron app.getPath('log')
API.
- on Linux:
~/.config/{app name}/logs/log.log
- on macOS:
~/Library/Logs/{app name}/log.log
- on Windows:
%USERPROFILE%\AppData\Roaming\{app name}\logs\log.log
$ npm install electron-winston
import { Logger } from 'electron-winston/main'
const logger = new Logger()
logger.info('hello world')
- Register a listener in main process, so that you can use it in the renderer process.
import { Logger } from 'electron-winston/main'
const logger = new Logger()
logger.registerRendererListener()
- Expose the
Logger
API.
You can expose it in the specified preload script:
import { exposeLogger } from 'electron-winston/preload'
exposeLogger()
Or, you can expose it globally in the main process for all renderer processes:
import { useLogger } from 'electron-winston/main'
useLogger()
- Use it in the renderer process
import logger from 'electron-winston/renderer'
logger.info('hello world')
MIT copyright © 2024-present alex wei