Glogg Global Logger

2.2.0 · active · verified Sun Apr 19

Glogg is a global logging utility designed for Node.js environments, primarily associated with the Gulp.js build system. It offers a straightforward, event-emitter-based interface for namespaced logging. The current stable version is 2.2.0. Releases are infrequent but occur when features or maintenance are required, typically in conjunction with updates within the Gulp ecosystem. A key differentiator is its reliance on `sparkles` (an augmented EventEmitter) to create loggers that emit events for different log levels (debug, info, warn, error). This architecture allows various parts of an application to retrieve a logger by its namespace and subscribe to specific log events, facilitating decoupled log handling. It supports `util.format()` for string interpolation, enabling printf-style logging, and can also log any data type directly. A critical operational aspect is that `error` events *must* be handled by at least one listener to prevent the Node.js process from crashing.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to create namespaced loggers, subscribe to different log levels (info, error), and emit various types of messages using `util.format()` style string interpolation and direct object logging. It explicitly highlights the critical error handling requirement to prevent process crashes.

const getLogger = require('glogg');

// Create a logger for a specific namespace
const mainLogger = getLogger('my-app');

// Create another logger for a different module
const dataModuleLogger = getLogger('data-processor');

// Listen for 'info' events from the 'my-app' namespace
mainLogger.on('info', (message) => {
  console.log(`[MainApp Info Listener]: ${message}`);
});

// IMPORTANT: You *must* handle 'error' events, or the process will crash.
mainLogger.on('error', (errMessage) => {
  console.error(`[MainApp Error Handler]: CRITICAL! ${errMessage}`);
  // In a real application, you might exit, log to a different system, etc.
});

// Log various types of messages
mainLogger.debug('This is a verbose debug message at %s.', new Date().toLocaleTimeString());
mainLogger.info('Application started successfully at %s.', new Date().toISOString());
mainLogger.warn('A configuration setting is missing, falling back to default.');
mainLogger.error('Failed to connect to database: Connection refused!');

// Log without string formatting - all arguments are emitted directly
dataModuleLogger.info({ event: 'data_processed', count: 123, status: 'success' });
dataModuleLogger.debug(['debug array', { key: 'value' }]);

// Demonstrates a message from a different logger
dataModuleLogger.warn('Data processing took longer than expected.');

// Output from a listener that applies custom filtering (conceptual)
// For instance, only process warnings from 'data-processor' in a specific way
dataModuleLogger.on('warn', (msg) => {
    if (msg.includes('longer than expected')) {
        console.log(`[Special Data Warn]: Specific issue noted: ${msg}`);
    }
});

// Simulate another error (this would also crash if not handled by mainLogger's handler)
// mainLogger.error('Another critical failure point!');

view raw JSON →