Log Driver

1.2.7 · abandoned · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

Demonstrates how to get the default logger, configure a logger with custom levels and thresholds, and apply a custom JSON formatting function, highlighting its stdout-centric design.

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

view raw JSON →