Essential logging functions providing multiple severity levels and flexible message formatting. Supports both simple string messages and complex object serialization with automatic type detection.
Standard log levels from most to least critical.
/**
* Log an error message - highest priority
* @param params - Any number of values to log (strings, objects, errors, etc.)
*/
error(...params: any[]): void;
/**
* Log a warning message
* @param params - Any number of values to log
*/
warn(...params: any[]): void;
/**
* Log an informational message - default level
* @param params - Any number of values to log
*/
info(...params: any[]): void;
/**
* Log a verbose message - detailed information
* @param params - Any number of values to log
*/
verbose(...params: any[]): void;
/**
* Log a debug message - development information
* @param params - Any number of values to log
*/
debug(...params: any[]): void;
/**
* Log a silly message - most detailed level
* @param params - Any number of values to log
*/
silly(...params: any[]): void;
/**
* Alias for info() method
* @param params - Any number of values to log
*/
log(...params: any[]): void;Usage Examples:
const log = require('electron-log');
// String messages
log.error('Application failed to start');
log.warn('Configuration file not found, using defaults');
log.info('User logged in successfully');
log.debug('Processing 150 items');
// Multiple parameters
log.info('User action:', 'login', { userId: 123, timestamp: new Date() });
// Object logging
log.debug('Response data:', {
status: 200,
data: { users: ['Alice', 'Bob'] },
headers: { 'content-type': 'application/json' }
});
// Error objects
try {
throw new Error('Something went wrong');
} catch (error) {
log.error('Caught exception:', error);
}Add custom log levels for application-specific needs.
/**
* Add a custom log level
* @param level - Name of the new log level
* @param index - Position in the priority order (0 = highest priority)
*/
addLevel(level: string, index?: number): void;Usage Examples:
const log = require('electron-log');
// Add custom levels
log.addLevel('critical', 0); // Higher priority than error
log.addLevel('trace', 6); // Lower priority than silly
// Use custom levels
log.critical('System is shutting down');
log.trace('Entering function processData()');
// Access dynamically
log['critical']('Dynamic level usage');Low-level message processing for custom logging workflows.
/**
* Process a log message through the transport system
* @param message - Complete log message object
* @param options - Processing options
*/
processMessage(
message: LogMessage,
options?: { transports?: Transport[] | string[] }
): void;Usage Examples:
const log = require('electron-log');
// Manual message processing
log.processMessage({
data: ['Custom message', { detail: 'info' }],
date: new Date(),
level: 'info',
logId: 'custom-logger'
});
// Process with specific transports only
log.processMessage({
data: ['File only message'],
date: new Date(),
level: 'debug'
}, {
transports: ['file']
});Access the underlying Logger class and functions.
interface LoggerAccess {
/** Direct access to Logger class for creating instances */
Logger: typeof Logger;
/** Object containing only log functions (error, warn, info, etc.) */
functions: LogFunctions;
/** Default logger instance */
default: Logger;
}Usage Examples:
const log = require('electron-log');
// Access logger functions only
const { error, warn, info } = log.functions;
info('Using extracted functions');
// Create new logger instance
const customLogger = log.create({ logId: 'module-a' });
customLogger.info('Message from custom logger');
// Access Logger class
const { Logger } = log;
const anotherLogger = new Logger({
logId: 'another-logger',
levels: ['error', 'warn', 'info']
});In renderer processes with preload scripts, logger functions are available globally.
declare global {
const __electronLog: LogFunctions;
interface Window {
__electronLog: LogFunctions;
}
}Usage Examples:
// In renderer process (when preload is configured)
__electronLog.info('Message from renderer process');
window.__electronLog.error('Error in renderer');
// Check if available
if (typeof __electronLog !== 'undefined') {
__electronLog.debug('Global logger available');
}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;
}
interface LogMessage {
/** Any arguments passed to a log function */
data: any[];
/** When the log entry was created */
date: Date;
/** From error to silly */
level: LogLevel;
/** Id of Logger instance */
logId?: string;
/** Message scope label */
scope?: string;
/** Variables used by formatter */
variables?: Variables;
}
type LogLevel = 'error' | 'warn' | 'info' | 'verbose' | 'debug' | 'silly';