Pretty logger for Electron apps
By default, logs from the renderer process don't show up in the terminal. Now they do.
You can use this module directly in both the main and renderer process.
npm install electron-timber
Requires Electron 30 or later.
Main process:
import {app, BrowserWindow} from 'electron';
import logger from 'electron-timber';
let mainWindow;
(async () => {
await app.whenReady();
mainWindow = new BrowserWindow();
await mainWindow.loadURL(…);
logger.log('Main log');
logger.error('Main error');
const customLogger = logger.create({name: 'custom'});
customLogger.log('Custom log');
})();
Renderer process:
import logger from 'electron-timber';
logger.log('Renderer log');
logger.error('Renderer error');
Logging will be prefixed with either main
or renderer
depending on where it comes from.
Logs from the renderer process only show up if you have required electron-timber
in the main process.
The methods are bound to the class instance, so you can do: const log = logger.log; log('Foo');
.
Like console.log
.
Like console.warn
.
Like console.error
.
Like console.time
.
Like console.timeEnd
.
Log each line in a stream.Readable
. For example, child_process.spawn(…).stdout
.
Same as streamLog
, but logs using console.warn
instead.
Same as streamLog
, but logs using console.error
instead.
Create a custom logger instance.
You should initialize this on module load so prefix padding is consistent with the other loggers.
Type: object
Type: string
Name of the logger. Used to prefix the log output. Don't use main
or renderer
.
Type RegExp
Ignore lines matching the given regex.
Type: string
Can be info
(log everything), warn
(log warnings and errors), or error
(log errors only). Defaults to info
during development and warn
in production.
Gets the default options (across main
and renderer
processes).
Sets the default options (across main
and renderer
processes).
Type: object
Same as the options
for create()
.
You can show the output of only a subset of the loggers using the environment variable TIMBER_LOGGERS
. Here we show the output of the default renderer
logger and a custom unicorn
logger, but not the default main
logger:
TIMBER_LOGGERS=renderer,unicorn electron .