Hackable console logger for Node.js applications with 17 out-of-the-box logger types and advanced features including integrated timers, scoped loggers, secrets filtering, and custom pluggable loggers.
—
Create and configure custom logger types with personalized badges, colors, labels, and behavior. Custom loggers allow you to extend Signale with domain-specific logging types while maintaining consistent styling and functionality.
Create custom Signale instances with personalized logger types and configuration.
/**
* Creates a new Signale instance with custom configuration
* @param options - Configuration object for the instance
*/
const { Signale } = require('signale');
const customLogger = new Signale(options);
interface SignaleOptions {
disabled?: boolean; // Disable all logging (default: false)
interactive?: boolean; // Enable interactive mode (default: false)
logLevel?: LogLevel; // Set minimum log level (default: 'info')
scope?: string | string[]; // Set logger scope name(s)
secrets?: (string | number)[]; // Array of secrets to filter from logs
stream?: WritableStream | WritableStream[]; // Output stream(s) (default: process.stdout)
types?: Record<string, LoggerType>; // Custom logger type definitions
timers?: Map<string, number>; // Pre-existing timers map
}
type LogLevel = 'info' | 'timer' | 'debug' | 'warn' | 'error';
type WritableStream = NodeJS.WritableStream;Define custom logger types with specific visual styling and behavior.
interface LoggerType {
badge?: string; // Icon/symbol for the logger (Unicode supported)
color?: ChalkColor; // Color name from chalk library
label?: string; // Text label displayed next to badge
logLevel?: LogLevel; // Minimum level for this logger to output
stream?: WritableStream | WritableStream[]; // Custom output stream(s) for this logger
}
// Supported chalk colors
type ChalkColor =
| 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white'
| 'gray' | 'grey' | 'blackBright' | 'redBright' | 'greenBright' | 'yellowBright'
| 'blueBright' | 'magentaBright' | 'cyanBright' | 'whiteBright';Usage Examples:
const { Signale } = require('signale');
// Define custom logger types
const options = {
types: {
remind: {
badge: '**',
color: 'yellow',
label: 'reminder',
logLevel: 'info'
},
santa: {
badge: '🎅',
color: 'red',
label: 'santa',
logLevel: 'info'
},
rocket: {
badge: '🚀',
color: 'cyan',
label: 'launch',
logLevel: 'info'
}
}
};
const custom = new Signale(options);
// Use custom loggers (automatically added as methods)
custom.remind('Update the documentation');
custom.santa('Ho ho ho! Check your code on line 42');
custom.rocket('Deployment initiated');Customize existing default logger types by redefining them in the types option.
Usage Examples:
const { Signale } = require('signale');
// Override default error and success loggers
const options = {
types: {
error: {
badge: '!!',
color: 'red',
label: 'FATAL ERROR'
},
success: {
badge: '++',
color: 'green',
label: 'HUGE SUCCESS'
}
}
};
const custom = new Signale(options);
// Compare default vs custom
const defaultLogger = new Signale();
defaultLogger.error('Default error message'); // ✖ error Default error message
defaultLogger.success('Default success message'); // ✔ success Default success message
custom.error('Custom error message'); // !! FATAL ERROR Custom error message
custom.success('Custom success message'); // ++ HUGE SUCCESS Custom success messageConfigure different output streams for individual logger types.
Usage Examples:
const { Signale } = require('signale');
const fs = require('fs');
// Create custom streams
const errorStream = fs.createWriteStream('errors.log');
const debugStream = fs.createWriteStream('debug.log');
const options = {
stream: process.stderr, // Default stream for all loggers
types: {
error: {
// Error logs go to both console and file
stream: [process.stderr, errorStream]
},
debug: {
// Debug logs only go to file
stream: debugStream,
color: 'gray',
label: 'debug'
},
custom: {
badge: '🔧',
color: 'blue',
label: 'custom',
// Uses default stream (process.stderr)
}
}
};
const logger = new Signale(options);
logger.error('This appears in console AND errors.log');
logger.debug('This appears only in debug.log');
logger.custom('This appears in console only');Combine default loggers with custom ones in a single instance.
Usage Examples:
const { Signale } = require('signale');
const options = {
types: {
// Add custom loggers alongside defaults
deploy: {
badge: '🚀',
color: 'magenta',
label: 'deploy',
logLevel: 'info'
},
security: {
badge: '🔒',
color: 'red',
label: 'security',
logLevel: 'warn'
}
}
};
const logger = new Signale(options);
// Use both default and custom loggers
logger.info('Application started'); // Default logger
logger.deploy('Deploying to production'); // Custom logger
logger.success('Deployment completed'); // Default logger
logger.security('Suspicious activity detected'); // Custom logger
logger.error('Deployment failed'); // Default loggerAccess and modify logger types at runtime through the instance properties.
Usage Examples:
const { Signale } = require('signale');
const logger = new Signale();
// Access current options (readonly)
console.log(logger.currentOptions);
// {
// config: {...},
// disabled: false,
// types: {...},
// interactive: false,
// timers: Map {},
// stream: [object Object],
// secrets: [],
// logLevel: 'info'
// }
// Create new instance with additional types
const extendedOptions = {
...logger.currentOptions,
types: {
...logger.currentOptions.types,
newType: {
badge: '⭐',
color: 'yellow',
label: 'special'
}
}
};
const extended = new Signale(extendedOptions);
extended.newType('This is a new logger type');Install with Tessl CLI
npx tessl i tessl/npm-signale