Skip to content

constructor

constructor(config?: ZylogConfig)

The constructor initializes the logger’s internal state, merges user-provided configuration with library defaults, and registers signal listeners for SIGINT, SIGTERM, and exit.

ParameterTypeDescription
configZylogConfigOptional object to customize prefixes, levels, and formatting.

Standard setup for a console-only logger.

import { Zylog } from 'zylog';
const log = new Zylog({
prefix: 'app',
level: 'info',
});

Configuring multi-file output for different severity levels.

const log = new Zylog({
level: 'debug',
streams: {
all: 'logs/combined.log',
levels: {
error: 'logs/critical-errors.log',
fatal: 'logs/system-crashes.log',
},
},
});
// Initialize the file streams after construction
log.createStream();

Overriding labels and disabling colors for specific environments.

const log = new Zylog({
labels: {
warn: '!!',
error: 'ERR',
},
colors: 0, // Completely disable ANSI colors
});