npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

dev-loggers

v3.1.1

Published

Minimal API and resource usage logging functionality. Supports namespaces, colors, and options, as well as LogModules for external classes to hook into the logging system. Includes basic Logger, PerformanceLogger, and BufferedLogger.

Readme

dev-loggers

Minimal, zero-dependency logging library.

  • Global singleton instances (namespaces)
  • Support for colorization and other options
  • Logger, PerformanceLogger, BufferedLogger

Installation

npm install dev-loggers

Quick Start

Import the logger factory functions for the type of logger you need, and retrieve an instance using a namespace as first argument.

If using these factory functions, all loggers with the same namespace use the global instance of that logger across all files.

// import
import { getLogger, getPerformanceLogger, getBufferedLogger } from 'dev-loggers';

// instantiate and get methods, at the top of a file
const { log, error, warn } = getLogger('MyService');

// outputs to console "MyService: message"
log('message');

// disable or set a color for the logger:
const { log } = getLogger('MyService', { enabled: false, color: 'blue' });

Note: If you call getLogger('namespace') with the same namespace in multiple files, it will use the same instance, but with the last configured options (if they happen to differ).

You can also instantiate a Logger instance directly, and calling the log methods on it. However note that these will not be managed by the LoggerRegister, and therefore not be singleton instances.

import { Logger } from 'dev-loggers';

const logger = new Logger(); // namespace is optional

logger.log('message');

Logger Types

1. Logger (Basic)

Standard logging with namespacing, colors, and customization options. Perfect for general application logging.

import { getLogger } from 'dev-loggers';

const { log, warn, error } = getLogger('MyApp');

log('Application started');
warn('Low memory warning');
error('Connection failed');

Output:

MyApp: Application started
MyApp: ⚠️ Warning: Low memory warning
MyApp: 🛑 Error! Connection failed

2. PerformanceLogger

Extends Logger to measure and display time elapsed between log calls with the same ID. Ideal for profiling and performance monitoring.

import { getPerformanceLogger } from 'dev-loggers';

const { log } = getPerformanceLogger('Performance');

log('(render)', 'Starting render');
// ... do work ...
log('(render)', 'Render complete');  // Shows elapsed time

Output:

Performance: (render) Starting render
Performance: (render) Render complete (142ms)

Additional Methods:

  • printCounts() - Display call count statistics for all IDs
  • reset() - Clear all performance data
  • time(id) - Get elapsed time for an ID
  • incr(id) - Increment counter for an ID

3. BufferedLogger

Extends Logger to accumulate log messages and output them all at once. Useful for batch operations or conditional logging.

import { getBufferedLogger } from 'dev-loggers';

const { log, flush } = getBufferedLogger('Batch');

log('Processing item 1');
log('Processing item 2');
log('Processing item 3');

flush();  // Outputs all buffered messages

Additional Methods:

  • flush() - Output all buffered messages and clear buffer
  • clear() - Clear buffer without outputting
  • getBufferSize() - Get current buffer size

Customization

Logger Options

All logger types accept an options object as the second parameter:

const logger = getLogger('MyApp', {
  color: 'cyan',           // Namespace color
  enabled: true,           // Enable/disable logging
  prefix: '[DEBUG]',       // Text before each message
  postfix: '✓'             // Text after each message
});

Available Options:

  • color - Color for the namespace (cyan, red, green, yellow, blue, magenta, white)
  • enabled - Enable or disable this logger
  • prefix - String to prepend to all messages
  • postfix - String to append to all messages

PerformanceLogger Options

const perfLogger = getPerformanceLogger('Perf', {
  logCounts: true,    // Track call counts
  showIds: true       // Show IDs in output
});

BufferedLogger Options

const bufLogger = getBufferedLogger('Buffer', {
  maxBufferSize: 500  // Auto-flush when buffer exceeds this size
});

Standalone Functions

You can use simple standalone logging functions without creating logger instances, which will just format and log to the console:

import { log, warn, error } from 'dev-loggers';

log('Simple message');
warn('Warning message');
error('Error message');

Advanced Features

LogModules - Custom Log Handlers

Register external classes to receive all log events for custom processing (e.g., sending to external services, UI panels, etc.):

import { addLogModule } from 'dev-loggers';
import { LogModule, LogEvent } from 'dev-loggers';

class CustomLogHandler implements LogModule {
  onLog(event: LogEvent) {
    // event.namespace - the logger's namespace
    // event.args - the log arguments
    this.sendToExternalService(event);
  }
}

addLogModule(new CustomLogHandler());

Global Controls

import { setLogAllMode, printLogCounts } from 'dev-loggers';

// Enable/disable all loggers
setLogAllMode(true);

// Enable only specific namespaces
setLogAllMode(true, ['MyApp', 'Database']);

// Print performance statistics for all PerformanceLoggers
printLogCounts();s

Configuration

The library respects these environment-level configurations:

  • LOG_COLORS_ENABLED - Enable/disable color output (useful to set this ENV on remote servers that don't support colors)
  • LOG_COLOR_DEFAULT - Set a default color for logs from these modules
  • LOG_ERRORS_ALWAYS - Log errors even when logger is disabled
  • LOG_WARNINGS_ALWAYS - Log warnings even when logger is disabled
  • LOG_ERROR_TRACES - Include stack traces after each error log