Skip to content

alex8088/electron-winston

Repository files navigation

electron-winston

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

Install

$ npm install electron-winston

Usage

Using in Electron Main Process

import { Logger } from 'electron-winston/main'

const logger = new Logger()

logger.info('hello world')

Using in Electron Renderer Process

  1. 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()
  1. 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()
  1. Use it in the renderer process
import logger from 'electron-winston/renderer'

logger.info('hello world')

License

MIT copyright © 2024-present alex wei

About

Simple logger for Electron app based on winston.

Resources

License

Stars

Watchers

Forks

Packages

No packages published