You can continue to use some older version or migrate to the latest. Here are documentation and code snapshot for older releases: v2, v3, v4.
If you would like to upgrade to the latest version, check the changelog and migration guide below.
Node.js 14 or Electron 13 is required.
npm install electron-log@5
In the latest few years many restrictions were added to a renderer process by default. It forces me to rethink electron-log architecture. So now the only way of implementing logging in a renderer process is move all the logic to the main process.
So now, the logger should be configured in the main process.
To make it possible for a renderer process to communicate the main process, it should be initialized in the main process before the first window is created:
main.js
import log from 'electron-log/main';
// It preloads electron-log IPC code in renderer processes
log.initialize();
After that, you can use the library as before.
renderer.ts
import log from 'electron-log/renderer';
log.info('Log from the renderer');
See initialize doc for more information.
To make callback names more obvious, some options where renamed:
- file.resolvePath -> file.resolvePathFn
- file.archiveLog -> file.archiveLogFn
- remote.onError -> remote.processErrorFn({ error, message, request })
- remote.transformBody -> remote.makeBodyFn({ logger, message, transport })
- log.catchErrors -> log.errorHandler.startCatching
npm install electron-log@latest
If you just use electron-log with default configuration, you only need to know that a default log file path was changed.
-
Default log path was changed on Linux and Windows to be more compatible with
app.getPath('logs')
of Electron:~/.config/{app name}/log.log →
~/.config/{app name}/logs/{process type}.log
%USERPROFILE%\AppData\Roaming\{app name}\log.log →
%USERPROFILE%\AppData\Roaming\{app name}\logs\{process type}.log
If you need to keep old file paths, you can override
file.resolvePath
-
file.fileName
is nowmain.log
,renderer.log
orworker.log
depending on process type -
new option
file.resolvePath
allows overriding default log path. Here is default implementation:log.transports.file.resolvePath = (variables) => { return path.join(variables.libraryDefaultDir, variables.fileName); }
- new method
file.getFile()
was added. It allows to manipulate the current log file.
- new method
-
The following file transport options and methods are deprecated and will be removed in v5:
file.file
, usefile.resolvePath
insteadfile.bytesWritten
, usefile.getFile().bytesWritten
insteadfile.fileSize
, usefile.getFile().size
insteadfile.clear()
, usefile.getFile().clear()
insteadfile.findLogPath()
, usefile.getFile().path
insteadfile.init()
, doesn't matter anymore
If you change some options of these transport, just use the same options of
ipc
transport instead.
npm install electron-log@latest
In v3 each process is configured separately. So if you change some options, you should apply the changed both in main and renderer processes.
Another changes:
- require
electron-log/main
andelectron-log/renderer
is deprecated. transports.file.level
is default to 'silly'.transports.file.stream
andstreamConfig
options are removed. Instead, you can use one of the following options:file
,fileName
,writeOptions
.rendererConsole
andmainConsole
transports are disabled by default for a packaged application.