A lightweight, zero-dependency logger for Node.js with file logging, error stacks, and console-style usage.
This package is designed for developers who want simple, predictable logging without pulling in large logging frameworks.
- ✅ Zero dependencies
- ✅ Supports
info,warn, anderrorlevels - ✅ Console-style logging (multiple arguments like
console.log) - ✅ Automatic error stack trace logging
- ✅ Logs stored by date and level
- ✅ Optional JSON logs (production-friendly)
- ✅ Optional size-based log rotation
- ✅ Async, non-blocking file writes
- ✅ Backward compatible across all v1.x versions
npm i node-error-logger.jsconst Logger = require('node-error-logger.js');
Logger.info('Application started');
Logger.warn('Low memory warning');
Logger.error('Something went wrong');This works exactly the same as earlier versions.
Just like console.log, you can pass multiple values:
Logger.info('User created', userId, userData);
Logger.warn('Invalid input', { field: 'email' });Extra values are treated as metadata.
Pass an Error anywhere in the arguments:
try {
throw new Error('Database connection failed');
} catch (err) {
Logger.error('Unhandled exception', err, { retry: false });
}✔ Logs the error message ✔ Logs the full stack trace ✔ No extra configuration required
Logs are written to the application root:
logs/
├── info/
│ └── 2025-01-01-info.log
├── warn/
│ └── 2025-01-01-warn.log
└── error/
└── 2025-01-01-error.log
Ideal for production environments and log processors.
const Logger = require('node-error-logger.js');
const logger = Logger.createLogger({ json: true });
logger.error('Payment failed', new Error('timeout'), { orderId: 123 });{
"timestamp": "2025-01-01T12:00:00.000Z",
"level": "error",
"message": "Payment failed",
"meta": [{ "orderId": 123 }],
"error": {
"name": "Error",
"message": "timeout",
"stack": "..."
}
}Enable size-based log rotation to prevent large log files.
const logger = Logger.createLogger({
rotate: true,
maxSizeMB: 10
});- Rotation is disabled by default
- Old files are renamed with a timestamp
Logs informational messages.
Logs warnings.
Logs errors and automatically captures stack traces when an Error is provided.
Creates a new logger instance with custom options.
| Option | Type | Default | Description |
|---|---|---|---|
json |
boolean | false |
Enable JSON log output |
rotate |
boolean | false |
Enable size-based log rotation |
maxSizeMB |
number | 5 |
Max log file size before rotation |
All existing usage patterns are fully supported in all v1.x releases.
New features are:
- optional
- opt-in
- non-breaking
- Simple
- Lightweight
- Predictable
- Ideal for small services, scripts, and APIs
- A replacement for Winston or Pino.
- A plugin-based logging framework.
- Designed for massive distributed systems.
If you need advanced transports or integrations, a full-featured logger may be a better fit.
MIT © Mohammad Moiz Ali (MAKSTYLE119)