Skip to content

πŸš€ lightweight logging β€’ supports level based filtering and tagging β€’ weighs in at around 500 bytes

License

Notifications You must be signed in to change notification settings

rmartone/missionlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

missionlog

NPM version Coverage Status

πŸš€ missionlog is a lightweight, 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


✨ 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.
βœ… Blazing Fast Performance – O(1) log level lookups for minimal overhead.
βœ… TypeScript-First – Full type safety, no need for @types.
βœ… Works Everywhere – Browser, Node.js, Firebase, AWS Lambda etc.

πŸ“¦ Installing

npm i missionlog  

🎯 Focus on What Matters, When It Matters

missionlog can filter logs dynamically by level or tag to avoid clutter and help you focus on what's important.

πŸš€ Example

import { DEFAULT_TAG, log, LogLevel, LogLevelStr, tag } from "missionlog";
import chalk from "chalk";

// Tags aren't required., This works just like console
log.error("Alert! Evil twin detected!");

// Use the built-in **"Dummy"** logger and becomes a no-op
log.info(tag.Engineering, "Engaging warp drive! Destination: The Final Frontier.");

// Assign tags levels, (TRACE < DEBUG < INFO < WARN < ERROR < OFF)
log.init({ Engineering: LogLevel.INFO, Transporter: LogLevel.DEBUG });

// Log with a tag
log.info(tag.Engineering, "Warp Factor 9!");

// Override the built-in **Dummy** logger with a custom behavior
log.init({ Engineering: LogLevel.INFO }, createLogHandler());

// Engineering's level is INFO+ so this gets logged!
log.info(tag.Engineering, "Warp Factor 5.");

// Gets filtered since Engineering is INFO+
log.debug(tag.Engineering, "Warp Factor 9!");

// Update tag levels and override default (INFO)
log.init({
  Engineering: LogLevel.TRACE,
  [DEFAULT_TAG]: LogLevel.ERROR, // used for logs without a tag
  Transporter: LogLevel.DEBUG,
});

// Log an error
const error = new Error("Warp core breach!");
log.error(tag.Engineering, "🚨 Red Alert!", error.message);

// Show some color!
log.debug(tag.Transporter, "✨ Beam me up, Scotty!");

// Log objects properly
log.warn(tag.Transporter, "Transporter anomaly detected,", { evilTwin: true });

// Replace dummy logger with custom behavior
function createLogHandler() {
  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.green, method: console.log },
    DEBUG: { color: chalk.magenta, method: console.log },
    TRACE: { color: chalk.cyan, method: console.log },
    OFF: { color: () => '', method: () => {} }, // No-op
  };

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

Example Image


πŸ“„ License

MIT License
Β© 2019-2025 Ray Martone


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

About

πŸš€ lightweight logging β€’ supports level based filtering and tagging β€’ weighs in at around 500 bytes

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published