Skip to content

Advanced, pluggable logger for Node.js with multiple transport and formatting options.

License

Notifications You must be signed in to change notification settings

SourceRegistry/node-logger

Repository files navigation

🧠 @sourceregistry/node-logger – Advanced Logging Framework [WORK IN PROGRESS]

A powerful, pluggable TypeScript logger for Node.js applications.
Supports JSON, text, CEF, and Syslog formatting, multiple transport targets (console, file, HTTP, Elasticsearch), and auto-flush strategies for production-grade logging.


🚀 Features

  • Log Levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL
  • Formatters:
    • JSONFormatter – machine-readable
    • TextFormatter – human-friendly
    • CEFFormatter – Common Event Format for SIEM
    • SyslogFormatter – Syslog-compatible format
  • Transports:
    • ConsoleTransport
    • FileTransport, BufferedFileTransport, SmartFileTransport
    • HTTPTransport, ElasticsearchTransport
    • WorkerTransport – offload to worker thread
  • Auto-flushing: Configurable by interval, size, severity, and idle timeout
  • Tagging & Contextual Logging
  • Asynchronous-safe, fault-tolerant design

📦 Installation

npm install @sourceregistry/node-logger

🛠 Usage

Basic Logger

import { Console, LogLevel } from '@sourceregistry/node-logger';

const logger = Console(LogLevel.DEBUG);
logger.info('App started');
logger.debug('Debugging details');

File Logger with JSON output

import { File } from '@sourceregistry/node-logger';

const fileLogger = File('./logs/app.log');
fileLogger.info('Writing to log file');

Elasticsearch Integration

import { Elasticsearch } from '@sourceregistry/node-logger';

const esLogger = Elasticsearch({
  endpoint: 'https://es.example.com/_bulk',
  apiKey: 'your-api-key',
  index: 'logs'
});

esLogger.error('Something went wrong!');

🧩 Advanced Features

Smart File Logging

import { SmartFileTransport, Logger, LogLevel } from '@sourceregistry/node-logger';

const logger = new Logger(LogLevel.INFO, [
  new SmartFileTransport('./logs/smart.log', undefined, LogLevel.INFO, {
    enabled: true,
    interval: 5000,
    onSize: 50,
    onLevel: LogLevel.ERROR,
    onIdle: 10000
  })
]);


// DEMONSTRATION:
logger.info('This will be buffered');
logger.debug('This will also be buffered');
// ... After 5 seconds, both logs auto-flush to disk

logger.error('This flushes immediately!'); // Because onLevel: ERROR
logger.warn('This will auto-flush based on smart rules'); // Because onLevel: WARNING

Tagged Logger

const taggedLogger = logger.withTags('auth', 'payment');
taggedLogger.info('User logged in');

🧼 Graceful Shutdown

process.on('SIGTERM', async () => {
  await logger.close();
  process.exit(0);
});

📜 License

Apache-2.0


🤝 Contributing

We welcome issues, feature requests, and pull requests!

About

Advanced, pluggable logger for Node.js with multiple transport and formatting options.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •