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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ahacad/logger

v0.1.1

Published

A lightweight, colorful, and feature-rich JavaScript logger

Readme

Logger

License: MIT

A lightweight, colorful, and feature-rich JavaScript logger with a beautiful interface and powerful functionality.

Features

  • Multiple Log Levels: TRACE, DEBUG, INFO, WARN, ERROR, SILENT
  • 🎨 Colored Output: Enhanced color support for both browsers and terminals
  • 🔀 Level Filtering: Disable logs below a certain level
  • 📝 Named Loggers: Support for module-specific loggers
  • 💾 Level Persistence: Save settings between sessions
  • Timestamps: Configurable timestamp output
  • 🔌 Formatters: Multiple output formats available
  • 🚀 Lightweight & Fast: Under 5KB minified and gzipped
  • 📱 Universal Support: First-class support for ESM and CommonJS
  • 💻 TypeScript Ready: Comprehensive TypeScript definitions

Installation

npm install logger

Quick Start

ESM (ECMAScript Modules)

// Modern ES module import
import logger from 'logger';

// Basic usage
logger.info('Application started');
logger.warn('Configuration missing, using defaults');
logger.error('Failed to connect to database', { host: 'localhost', port: 5432 });

CommonJS

// CommonJS require
const logger = require('logger');

// Basic usage
logger.info('Application started');
logger.warn('Configuration missing, using defaults');
logger.error('Failed to connect to database', { host: 'localhost', port: 5432 });

Named Loggers

// Module specific logger
const apiLogger = logger.getLogger('api');
apiLogger.setLevel('debug');
apiLogger.debug('Request received', { method: 'GET', path: '/users' });

// Customize output
logger
  .setLevel('info')     // Only show info and above
  .useColors(true)      // Enable colors
  .useTimestamps(true)  // Show timestamps
  .persist();           // Save settings to localStorage/cookies

Log Levels

The following log levels are available, in order of verbosity:

  • TRACE (0): Most verbose, for detailed debugging
  • DEBUG (1): Debug information
  • INFO (2): General information
  • WARN (3): Warnings (default level)
  • ERROR (4): Errors
  • SILENT (5): No logging

Colored Output

Logger supports colorized output across environments:

| Level | Browser | Terminal | Description | |-------|---------|----------|-------------| | TRACE | Cyan | Cyan | Detailed tracing information | | DEBUG | Green | Green | Debug-level messages | | INFO | Blue | Bright Blue | Informational messages | | WARN | Orange | Yellow | Warning messages | | ERROR | Red | Bright Red | Error messages |

Colors are automatically enabled based on environment detection and can be toggled with:

// Enable colors
logger.useColors(true);

// Disable colors
logger.useColors(false);

API Reference

Logger Methods

  • logger.trace(...args): Log at TRACE level
  • logger.debug(...args): Log at DEBUG level
  • logger.info(...args): Log at INFO level
  • logger.warn(...args): Log at WARN level
  • logger.error(...args): Log at ERROR level
  • logger.log(...args): Alias for debug

Configuration

  • logger.setLevel(level, persist?): Set the current log level
  • logger.getLevel(): Get the current log level as enum
  • logger.getLevelName(): Get the current log level name
  • logger.setDefaultLevel(level): Set the default log level
  • logger.resetLevel(): Reset to the default log level
  • logger.enableAll(persist?): Enable all logging (TRACE)
  • logger.disableAll(persist?): Disable all logging (SILENT)
  • logger.useColors(enable): Enable or disable colors
  • logger.useTimestamps(enable): Enable or disable timestamps
  • logger.persist(storage?): Enable log level persistence

Named Loggers

  • logger.getLogger(name): Get a named logger
  • logger.getLoggers(): Get all named loggers

Formatters

  • logger.setFormatter(formatter): Set custom formatter
  • logger.getFormatter(): Get current formatter

Custom Formatters

The library includes several built-in formatters:

  • DefaultFormatter: Includes timestamps, log level, and logger name
  • MinimalFormatter: Simple prefix with just the logger name
  • JsonFormatter: Structured JSON output

Example:

// ESM
import logger, { JsonFormatter } from 'logger';

// CommonJS
const { default: logger, JsonFormatter } = require('logger');

// Create a JSON formatter
const jsonFormatter = new JsonFormatter();

// Use it with the logger
logger.setFormatter(jsonFormatter);

// Or with a named logger
const apiLogger = logger.getLogger('api');
apiLogger.setFormatter(jsonFormatter);

You can create your own formatter by implementing the LogFormatter interface.

Module Compatibility

This logger provides first-class support for both ESM and CommonJS module systems:

ESM (ECMAScript Modules)

// Default import
import logger from 'logger';

// Named imports
import logger, { LogLevel, JsonFormatter } from 'logger';

CommonJS

// Direct require (default export)
const logger = require('logger');

// Destructured require
const { default: logger, JsonFormatter } = require('logger');

Browser Usage

Logger works great in browsers and includes automatic persistence using localStorage or cookies.

<script type="module">
  import logger from 'logger';
  logger.info('Logger loaded in browser');
  
  // Get a module-specific logger
  const uiLogger = logger.getLogger('ui');
  uiLogger.debug('UI component initialized');
</script>

Node.js Usage

Use the logger in Node.js applications:

// ESM
import logger from 'logger';
logger.info('Node.js application started');

// CommonJS
const logger = require('logger');
logger.info('Node.js application started');

// Named loggers work the same
const dbLogger = logger.getLogger('database');
dbLogger.info('Connected to database');

Examples

Check out the included examples:

  • example.cjs - CommonJS example
  • example.mjs - ES Modules example

Run them with:

# Build the library first
npm run build

# Run examples
npm run example:cjs
npm run example:esm

License

MIT