A dead simple logger module for Node.js. Provides console and file-based logging with support for log rotation, custom formatting, colored output, and robust error handling.
- π₯ Console and file logging
- π Log rotation with delete/archive strategies
- π§© Customizable log formatting
- π Colored log levels in console
- π§± Handles undefined/non-serializable messages
- π§ TypeScript type definitions included
- π ESM + CommonJS support
npm install deadslog
# or
bun add deadslogimport deadslog from "deadslog";
const logger = deadslog();
logger.info("Hello, world!");const logger = deadslog({
formatter: (level, message) => {
const timestamp = new Date().toLocaleString();
return `---\nTime: ${timestamp}\nLevel: ${level}\nMessage: ${message}\n---`;
},
});
logger.info("Custom formatted log!");const logger = deadslog({
fileOutput: {
enabled: true,
logFilePath: "./logs/app.log",
rotate: true,
maxLogSize: 1024 * 1024, // 1MB
maxLogFiles: 3,
onMaxLogFilesReached: "archiveOld", // or "deleteOld"
},
});
logger.info("This will be written to a file!");const deadslog = require("deadslog");
const logger = deadslog();
logger.info("Hello from CJS!");Returns a logger instance.
| Option | Type | Description |
|---|---|---|
consoleOutput.enabled |
boolean |
Enable console logging (default: true) |
consoleOutput.coloredCoding |
boolean |
Enable colored output using chalk (default: true) |
fileOutput.enabled |
boolean |
Enable file logging (default: false) |
fileOutput.logFilePath |
string |
File path for log output (required if file logging is enabled) |
fileOutput.rotate |
boolean |
Enable automatic log file rotation |
fileOutput.maxLogSize |
number |
Maximum log file size in bytes before rotation |
fileOutput.maxLogFiles |
number |
Number of rotated files to keep |
fileOutput.onMaxLogFilesReached |
string |
Rotation strategy: "deleteOld" or "archiveOld" |
formatter |
function |
Optional custom formatter for log messages |
minLevel |
string |
Minimum log level: trace, debug, info, success, warn, error, fatal |
filters.include |
string |
Word filter to include from log |
filters.exclude |
string |
Word filter to exclude from log |
trace(msg)debug(msg)info(msg)success(msg)warn(msg)error(msg)fatal(msg)flush()destroy()
Type definitions are included and will be picked up automatically.
const simpleFormatter = (level, message) => {
const timestamp = new Date().toISOString();
return `[${timestamp}] [${level}] ${message}`;
};[2025-05-03T13:45:21.123Z] [INFO] Application startedconst multilineFormatter = (level, message) => {
const timestamp = new Date().toLocaleString();
return `---\nTime: ${timestamp}\nLevel: ${level}\nMessage: ${message}\n---`;
};---
Time: 5/3/2025, 1:46:11 PM
Level: DEBUG
Message: Connected to database
---const csvFormatter = (level, message) => {
const timestamp = new Date().toISOString();
const escaped = message.replace(/"/g, '""');
return `"${timestamp}","${level}","${escaped}"`;
};"2025-05-03T13:47:02.789Z","ERROR","Failed to load module: ""auth.js"""const emojiFormatter = (level, message) => {
const emojis = {
trace: 'π',
debug: 'π',
info: 'βΉοΈ',
success: 'β
',
warn: 'β οΈ',
error: 'β',
fatal: 'π'
};
const timestamp = new Date().toISOString();
return `${emojis[level] || ''} [${timestamp}] ${level}: ${message}`;
};β
[2025-05-03T13:48:15.456Z] SUCCESS: Task completedconst jsonlFormatter = (level, message) => {
return JSON.stringify({
ts: Date.now(),
level,
message
});
};{"ts":1714740493123,"level":"INFO","message":"Something happened"}- Types file was not included in the package, causing issues for TypeScript users.
See CHANGELOG.md for previous versions and more details.
MIT