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

missionlog

v4.1.1

Published

πŸš€ lightweight TypeScript abstract logger β€’ level based filtering and optional tagging β€’ supports both ESM & CJS

Readme

missionlog

NPM version Coverage Status License: MIT


πŸš€ missionlog is a lightweight, high-performance structured logging package designed for performance, flexibility, and ease of use. It works as a drop-in replacement for console.log or ts-log, and offers both log level filtering, optional tag filtering, and customizable output handlingβ€”all in a tiny (~1KB) package.

βœ” Fully Typed (TypeScript) β€’ βœ” ESM & CJS Support β€’ βœ” Zero Dependencies β€’ βœ” 100% Coverage β€’ βœ” Optimized Performance


✨ Why Use missionlog?

  • Drop-in Replacement for console.log & ts-log – Start using it instantly!
  • Seamless Upgrade to Tagged Logging – Reduce log clutter and focus on what's important.
  • Configurable Log Levels – Adjust visibility for log level and tags at runtime.
  • Customizable Output – Send logs anywhere: console, JSON, cloud services.
  • Ultra-Fast Performance – Optimized with advanced caching and minimal memory allocation.
  • TypeScript-First – Full type safety with comprehensive JSDoc documentation.
  • Chainable API – All methods return the logger instance for method chaining.
  • Works Everywhere – Browser, Node.js, Firebase, AWS Lambda etc.

⚑ Performance & Efficiency

missionlog v4 has been optimized for high-performance applications:

  • Smart Caching – Level checks are cached to avoid repeated calculations
  • Minimal Memory Allocation – Reduced garbage collection with optimized array handling
  • Zero String Concatenation – Efficient cache keys using nested Map structures
  • Type-Safe Tag Access – Runtime validation with compile-time safety via proxy
  • Optimized Parameter Handling – Minimal array operations for better performance

Perfect for high-frequency logging scenarios like real-time applications, games, and data processing pipelines.


πŸ“¦ Installing

npm i missionlog

πŸš€ Getting Started

Basic Usage

Missionlog works as a drop-in replacement for console.log:

import { log } from 'missionlog';

// Works just like console.log
log.info('Hello, world!');
log.warn('Warning message');
log.error('Error occurred!');

// Chainable API for fluent logging
log.debug('Starting process').info('Process step 1 complete').warn('Process running slowly');

πŸ’‘ Usage Examples

Using Tags for Categorization

import { log, tag, LogLevel, DEFAULT_TAG } from 'missionlog';

// Configure logging levels for different tags
log.init({
  network: LogLevel.DEBUG,
  ui: LogLevel.INFO,
  [DEFAULT_TAG]: LogLevel.WARN, // Default level for uncategorized logs
});

// Log with type-safe tags - autocomplete shows available tags!
log.debug(tag.network, 'Connection established');
log.info(tag.ui, 'Component rendered');

// Typos in tags return undefined, preventing silent errors
log.debug(tag.netwrok, 'This will be logged without tag due to typo');

// Untagged logs use the DEFAULT_TAG level
log.debug("This won't be logged because DEFAULT_TAG is WARN");
log.error('This will be logged because ERROR > WARN');

Custom Log Handler (with Chalk)

import { log, LogLevel, LogLevelStr } from 'missionlog';
import chalk from 'chalk';

// Create a custom log handler
function createCustomHandler() {
  const logConfig: Record<LogLevelStr, { color: (text: string) => string; method: (...args: unknown[]) => void }> = {
    ERROR: { color: chalk.red, method: console.error },
    WARN: { color: chalk.yellow, method: console.warn },
    INFO: { color: chalk.blue, method: console.log },
    DEBUG: { color: chalk.magenta, method: console.log },
    TRACE: { color: chalk.cyan, method: console.log },
    OFF: { color: () => '', method: () => {} },
  };

  return (level: LogLevelStr, tag: string, message: unknown, params: unknown[]) => {
    const { method, color } = logConfig[level];
    const logLine = `[${color(level)}] ${tag ? tag + ' - ' : ''}${message}`;
    method(logLine, ...params);
  };
}

// Initialize with custom handler
log.init({ network: LogLevel.INFO, [DEFAULT_TAG]: LogLevel.INFO }, createCustomHandler());

// Check if specific levels are enabled before performing expensive operations
if (log.isDebugEnabled('network')) {
  // Only perform this expensive operation if DEBUG logs for 'network' will be shown
  const stats = getNetworkStatistics(); // Example of an expensive operation
  log.debug(tag.network, 'Network statistics', stats);
}

// Similarly for TRACE level
if (log.isTraceEnabled('ui')) {
  // Avoid expensive calculations when trace logging is disabled
  const detailedMetrics = calculateDetailedRenderMetrics();
  log.trace(tag.ui, 'UI rendering detailed metrics', detailedMetrics);
}

// The general method is still available for other log levels
if (log.isLevelEnabled(LogLevel.WARN, 'security')) {
  const securityCheck = performSecurityAudit();
  log.warn(tag.security, 'Security audit results', securityCheck);
}

⚠️ Breaking Changes in v4.0.0

Removed Enhanced Callback

The enhanced callback functionality has been removed to simplify the API:

  • ❌ log.setEnhancedCallback() method removed
  • ❌ LogCallbackParams interface removed
  • ❌ EnhancedLogCallback type removed

Migration: Use the standard callback in log.init() instead:

// ❌ Old way (v3.x)
log.setEnhancedCallback((params) => {
  const { level, tag, message, timestamp, params: extraParams } = params;
  console.log(`[${timestamp.toISOString()}] [${level}] ${message}`, ...extraParams);
});

// βœ… New way (v4.x)
log.init({}, (level, tag, message, params) => {
  const timestamp = new Date().toISOString();
  console.log(`[${timestamp}] [${level}] ${message}`, ...params);
});

πŸ“– API Reference

Log Methods

All logging methods support both tagged and untagged logging with full type safety:

  • log.trace(messageOrTag?, ...params) - Lowest verbosity level
  • log.debug(messageOrTag?, ...params) - Detailed debugging information
  • log.info(messageOrTag?, ...params) - Notable but expected events
  • log.log(messageOrTag?, ...params) - Alias for info()
  • log.warn(messageOrTag?, ...params) - Potential issues or warnings
  • log.error(messageOrTag?, ...params) - Error conditions

Configuration & Utilities

  • log.init(config?, callback?) - Configure log levels and custom handler
  • log.isLevelEnabled(level, tag?) - Check if a specific level would be logged for a tag
  • log.isDebugEnabled(tag?) - Convenience method to check if DEBUG level is enabled
  • log.isTraceEnabled(tag?) - Convenience method to check if TRACE level is enabled
  • log.reset() - Reset logger to initial state and clear all configurations

Type-Safe Tag Access

  • tag.{tagName} - Access registered tags with runtime validation
  • Returns the tag name if registered, undefined otherwise
  • Provides IDE autocomplete for registered tags

Log Levels (in order of verbosity)

  1. LogLevel.TRACE - Most verbose
  2. LogLevel.DEBUG
  3. LogLevel.INFO - Default level
  4. LogLevel.WARN
  5. LogLevel.ERROR
  6. LogLevel.OFF - No logs

πŸ–ΌοΈ Example Output

Example Image


🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check issues page or submit a pull request.


πŸ“„ License

MIT License Β© 2019-2025 Ray Martone


πŸš€ Install missionlog today and make logging clean, structured, and powerful!