npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

electron-timber

v2.0.0

Published

Pretty logger for Electron apps

Readme

electron-timber

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.

Install

npm install electron-timber

Requires Electron 44 or later.

Usage

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');

No preload setup is needed. The module registers its own preload script via session.registerPreloadScript() to share defaults with renderers.

Works with bundlers like Vite (including electron-vite). The renderer entry is browser-only and never bundles Node.js or Electron main-process APIs, so nodeIntegration is not required. If your bundler needs it to be explicit, import electron-timber/renderer in the renderer and electron-timber/main in the main process.

If you bundle the main process, webpack and rspack copy the preload script into the output automatically. Vite/Rollup and esbuild cannot do this, so mark electron-timber as external in the main process build. electron-vite already does this by default.

API

logger

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 imported electron-timber in the main process.

The methods are bound to the class instance, so you can do: const log = logger.log; log('Foo');.

log(…values)

Like console.log.

warn(…values)

Like console.warn.

error(…values)

Like console.error.

time(label?)

Like console.time.

label

Type: string
Default: 'default'

timeEnd(label?)

Like console.timeEnd. Does nothing when no timer with the label is running.

label

Type: string
Default: 'default'

streamLog(stream)

Log each line in a stream.Readable. For example, child_process.spawn(…).stdout.

streamWarn(stream)

Same as streamLog, but logs using console.warn instead.

streamError(stream)

Same as streamLog, but logs using console.error instead.

create(options?)

Create a custom logger instance.

You should initialize this on module load so prefix padding is consistent with the other loggers.

options

Type: object

name

Type: string

Name of the logger. Used to prefix the log output. Don't use main or renderer.

ignore

Type: RegExp

Ignore lines matching the given regex.

logLevel

Type: string
Default: 'info' when NODE_ENV is 'development', otherwise 'warn'

Can be info (log everything), warn (log warnings and errors), or error (log errors only).

timestamp

Type: boolean
Default: false

Prefix the output with the local time, for example 22:10:34 main › Log.

Only applies to the terminal output. Renderer logs are printed in the terminal by the main process, so use setDefaults() in the main process to add timestamps to them. In DevTools, use the “Show timestamps” setting instead.

logger.setDefaults({timestamp: true});
file

Type: boolean | string
Default: false

Also write the output to a file.

Use true to write to main.log in app.getPath('logs') (for example, ~/Library/Logs/<app name>/main.log on macOS), or a string with the absolute path to the file. The directory is created if it does not exist.

The logLevel, ignore, and TIMBER_LOGGERS filters also apply to the file. Lines are written without colors and with a timestamp, for example 2026-10-07T20:10:34.123Z [warn] main › Something. Lines are written synchronously, so the last lines before a crash are not lost.

Only applies in the main process. Renderer logs are written by the main process, so use setDefaults() in the main process to also write them to the file.

logger.setDefaults({file: true});
maxFileSize

Type: number
Default: 1048576 (1 MB)

The maximum size of the log file in bytes.

When the file reaches this size, it is renamed with .old added to the name (for example, main.old.log), replacing the previous one, and a new file is started, so at most about twice this size is kept on disk. Set it to 0 to never rotate the file.

logger.setDefaults({
	file: true,
	maxFileSize: 5 * 1024 * 1024
});

getDefaults()

Get the default options (across main and renderer processes).

Note: logLevel is returned in its internal numeric form.

setDefaults(options?) Main process only

Set the default options (across main and renderer processes). Renderer windows are notified automatically.

The name option is ignored.

It throws when called from a renderer.

options

Type: object

Same as the options for create() (except name).

hookConsole(options?)

Hook console methods (console.log, console.warn, etc.) to use electron-timber instead.

When called with no arguments, hooks the console in the current process. From the main process, pass {renderer: true} to also hook all current and future renderer consoles.

Electron security warnings are not sent to the terminal, as they are already visible in the DevTools console.

Returns a function to unhook the console methods.

options

Type: object

main

Type: boolean
Default: true when called with no arguments from the main process, otherwise false

Hook the console in the main process. Only applies in the main process.

renderer

Type: boolean
Default: true when called with no arguments from a renderer process, otherwise false

Hook the console in renderer processes. Can be set from the main process to hook all current and future renderers, or from a renderer to hook itself.

const unhook = logger.hookConsole({
	main: true,
	renderer: true
});

// Later...
unhook();

Note: Custom loggers created with create() do not have access to this method.

Toggle loggers

You can show the output of only a subset of the loggers using the environment variable TIMBER_LOGGERS. It must be set before the module is imported. 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 .

Colors

Colors are disabled when chalk detects that the output is not a TTY, which happens in some terminals and set-ups even though the output ends up somewhere that renders colors fine (Cmder/ConEmu, mintty, the VS Code debugger, Electron on Windows). Set FORCE_COLOR=1 to force colors in that case:

FORCE_COLOR=1 electron .

Related