CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-electron-log

Simple logging module for Electron, Node.js, and NW.js applications with multiple transport options

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Electron Log

Electron Log is a simple, powerful logging module specifically designed for Electron applications, but also compatible with Node.js and NW.js environments. It provides a comprehensive logging solution with multiple transport methods, automatic file system integration, and built-in IPC communication for seamless logging across main and renderer processes.

Package Information

  • Package Name: electron-log
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install electron-log

Core Imports

Context-aware import (auto-detects environment):

const log = require('electron-log');
import log from 'electron-log';

Environment-specific imports:

// Main process
const log = require('electron-log/main');

// Renderer process
const log = require('electron-log/renderer');

// Node.js
const log = require('electron-log/node');

// Preload script
require('electron-log/preload');
// Main process
import log from 'electron-log/main';

// Renderer process
import log from 'electron-log/renderer';

// Node.js
import log from 'electron-log/node';

Basic Usage

import log from 'electron-log';

// Initialize for renderer process (main process only)
log.initialize();

// Basic logging
log.error('Something went wrong');
log.warn('This is a warning');
log.info('Application started');
log.verbose('Verbose information');
log.debug('Debug information');
log.silly('Very detailed debug information');

// Custom scoped logging
const scopedLog = log.scope('auth');
scopedLog.info('User logged in');

// Configure transports
log.transports.file.level = 'debug';
log.transports.console.format = '{h}:{i}:{s} {text}';

// Error handling
log.errorHandler.startCatching();

Architecture

Electron Log is built around several key components:

  • Logger Core: Central Logger class managing log levels, transports, and message processing
  • Transport System: Pluggable output destinations (console, file, IPC, remote)
  • Context Detection: Automatic environment detection for main/renderer/node processes
  • IPC Bridge: Communication layer between main and renderer processes
  • Error Handling: Unhandled exception and promise rejection catching
  • Event Logging: Electron app and webContents event monitoring
  • Scoping: Message categorization and filtering system

Capabilities

Core Logging

Essential logging functions with multiple levels and flexible message formatting. Supports both simple string messages and complex object serialization.

interface LogFunctions {
  error(...params: any[]): void;
  warn(...params: any[]): void;
  info(...params: any[]): void;
  verbose(...params: any[]): void;
  debug(...params: any[]): void;
  silly(...params: any[]): void;
  log(...params: any[]): void; // Alias for info
}

Core Logging

Transport System

Multiple output destinations for log messages including console, files, IPC communication, and remote HTTP endpoints. Each transport is independently configurable.

interface Transport {
  (message: LogMessage): void;
  level: LogLevel | false;
  transforms: TransformFn[];
}

interface MainTransports {
  console: ConsoleTransport;
  file: FileTransport;
  ipc: Transport;
  remote: RemoteTransport;
}

interface RendererTransports {
  console: ConsoleTransport;
  ipc: Transport;
}

Transport System

Logger Management

Logger instance creation, configuration, and lifecycle management. Supports multiple logger instances with independent configurations and message buffering for batch processing.

interface Logger extends LogFunctions {
  logId: string;
  levels: string[];
  transports: { [key: string]: Transport | null };
  variables: Variables;
  hooks: Hook[];
  
  addLevel(level: string, index?: number): void;
  create(options: { logId: string }): Logger;
  processMessage(message: LogMessage, options?: { transports?: Transport[] | string[] }): void;
}

Logger Management

Error Handling

Automatic catching and logging of unhandled exceptions and promise rejections with customizable error processing and dialog display.

interface ErrorHandler {
  handle(error: Error, options?: ErrorHandlerOptions): void;
  setOptions(options: ErrorHandlerOptions): void;
  startCatching(options?: ErrorHandlerOptions): void;
  stopCatching(): void;
}

Error Handling

Event Logging

Automatic logging of Electron application and webContents events with customizable formatting and filtering.

interface EventLogger {
  format: string | ((input: EventFormatterInput) => unknown[]);
  level: LogLevel;
  scope: string;
  events: Record<EventSource, Record<string, boolean>>;
  formatters: Record<EventSource, Record<string, (input: EventFormatterInput) => object | unknown[]>>;
  
  setOptions(options: EventLoggerOptions): void;
  startLogging(options?: EventLoggerOptions): void;
  stopLogging(): void;
}

Event Logging

Message Scoping

Scoped logging for message categorization and filtering with automatic label padding and customizable formatting.

interface Scope {
  (label: string): LogFunctions;
  defaultLabel: string | false;
  labelPadding: boolean | number;
}

Message Scoping

Core Types

type LogLevel = 'error' | 'warn' | 'info' | 'verbose' | 'debug' | 'silly';
type LevelOption = LogLevel | false;

interface LogMessage {
  data: any[];
  date: Date;
  level: LogLevel;
  logId?: string;
  scope?: string;
  variables?: Variables;
}

interface Variables {
  processType: string;
  [name: string]: any;
}

type Hook = (
  message: LogMessage,
  transport?: Transport,
  transportName?: string,
) => LogMessage | false;

type TransformFn = (options: {
  data: any[];
  message: LogMessage;
  transport: Transport;
  logger: Logger;
}) => any;

Install with Tessl CLI

npx tessl i tessl/npm-electron-log

docs

core-logging.md

error-handling.md

event-logging.md

index.md

logger-management.md

scoping.md

transports.md

tile.json