Log Driver
Log Driver is a minimalistic Node.js logging framework, currently at version 1.2.7. It is designed exclusively to output all logs to standard output (stdout), following a Unix-like philosophy. Its core differentiator is the complete decoupling of log processing from the application itself, advocating for external tools and operating system pipes (e.g., `2>&1 | logger` or `>> somefile.log`) to handle persistence, routing, and filtering of logs. The package provides configurable log levels (e.g., error, warn, info, debug, trace) and allows for custom formatting functions, including JSON output. Unlike many contemporary logging libraries, Log Driver does not include built-in transports for files, network, or databases. The project appears to be abandoned, with its last publish occurring 8 years ago as of February 2018, implying no active release cadence or maintenance.
Common errors
-
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension in <module path> for <log-driver module path>
cause Attempting to `import` the CommonJS-only `log-driver` package in an ES Module context (e.g., a `.mjs` file or a project with `"type": "module"` in `package.json`).fixUse `const logDriver = require('log-driver');` instead of `import` statements. If your project is pure ESM, consider migrating to an ESM-compatible logging library. -
TypeError: logger.trace is not a function
cause The logger instance was initialized with a `level` option that is higher (less verbose) than 'trace', effectively disabling the `trace` method. For example, setting `level: 'info'` will disable `debug` and `trace` methods.fixEnsure the logger is configured with a sufficiently low `level` to enable the desired methods. For 'trace' output, initialize with `require('log-driver')({ level: 'trace' })` or lower. -
ReferenceError: require is not defined
cause `log-driver` is a Node.js-specific package that uses Node.js's `require` function, which is not available in client-side browser environments.fixThis package is not designed for browser use. For client-side logging, use browser-native `console` methods or a browser-compatible logging library (e.g., `loglevel`).
Warnings
- breaking The `log-driver` package is abandoned and has not received updates since February 2018. This implies a lack of security patches, bug fixes, and compatibility updates for newer Node.js versions or evolving ecosystem standards. Continued use in production environments is highly risky.
- gotcha This package is CommonJS-only and does not support ES Modules (`import`/`export`). Attempting to use `log-driver` in an ESM context will lead to runtime errors.
- gotcha Log Driver's design relies heavily on operating system-level piping for log persistence and transport (e.g., sending to files, syslog, or external services). It does not provide built-in transports like modern logging libraries.
- gotcha The package's `engines` field specifies Node.js `>=0.8.6`, which is an extremely old and unsupported version of Node.js. While it might still function on newer Node.js runtimes, unexpected behavior, deprecation warnings, or outright compatibility issues are highly probable due to unmaintained dependencies or breaking changes in Node.js itself.
Install
-
npm install log-driver -
yarn add log-driver -
pnpm add log-driver
Imports
- logger
import { logger } from 'log-driver';const logger = require('log-driver').logger; - default export (factory)
import customLogger from 'log-driver';
const customLogger = require('log-driver')({ level: 'info' }); - Logger instances
logger.log('info', 'message');logger.info('message');
Quickstart
const logDriver = require('log-driver');
// Get the default logger instance
const defaultLogger = logDriver.logger;
defaultLogger.info('Application started at %s', new Date().toISOString());
defaultLogger.warn('Potential issue: %j', {
severity: 'medium',
reason: 'Resource nearing limit'
});
defaultLogger.error(new Error('Something critical happened!'), 'An unexpected error occurred.');
// Configure a custom logger with specific levels and a lower threshold
const customLevelsLogger = logDriver({
levels: ['audit', 'critical', 'notify'],
level: 'critical' // Only log 'critical' and 'audit'
});
customLevelsLogger.audit('User %s performed action %s', 'admin', 'login');
customLevelsLogger.critical('Database connection lost!');
customLevelsLogger.notify('New update available (this will not show)'); // Below 'critical' level
// Demonstrate a custom formatter for JSON output
const jsonLogger = logDriver({
format: function() {
const args = Array.from(arguments);
const level = args.shift(); // First arg is the log level implicitly passed by the method
const timestamp = new Date().toISOString();
return JSON.stringify({
timestamp,
level,
message: args.map(arg => typeof arg === 'object' ? JSON.stringify(arg) : String(arg)).join(' ')
});
}
});
jsonLogger.info('This is a JSON log message', { data: 'example', id: 123 });
// To experience log-driver's full effect, run this script and pipe its output:
// node your-app.js 2>&1 | tee app.log | some-log-processor.js