JSPM

  • Created
  • Published
  • Downloads 4776
  • Score
    100M100P100Q118335F
  • License MIT

🔥 lightweight level based logging that weighs in at ~400 bytes 🔥

Package Exports

  • missionlog

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (missionlog) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

missionlog NPM version Build status Coverage Status Bundlephobia

Missionlog is an easy to use lightweight logging library that provides level based category filtering. Messages are logged when their level is greater than or equal to their category's level (ERROR > WARN > INFO). A category is a string that typically refers to a subsystem like "security" or "renderer". At initialization, each category is assigned a level. Granular control over your logs keeps them readable and uncluttered.

Features

  • Small footprint ~400 bytes with 0 dependencies
  • Simple JSON configuration
  • Filter by level
  • Filter by named category 'system' | 'whatever'
  • Flexible log event callback
    • Style terminal output with chalk
    • Send JSON to a cloud service like Loggly
    • Log strings and objects to the browser's console
  • API mirrors console.log logs objects and supports rest parameters
  • CommonJS module that works reliably with node or any browser through a bundler
  • Includes TypeScript definitions so no @types

Install

npm install missionlog

Initialize

// improt { log } from 'missionlog';
var log = require('missionlog').log;
// Set the max level to log for arbitrary categories
// where INFO > WARN > ERROR > OFF
log.init({ loader: 'INFO', security: 'ERROR', system: 'OFF' }, (level, category, msg, params) => {
  // then log the way that works best for you
  //  * style terminal output with chalk
  //  * send JSON to a cloud logging service like Splunk
  //  * log strings and objects to the browser's console
  console.log(`${level}: [${category}] `, msg, ...params);
});

Use

log.warn('loader', 'failed to load', url);
log.error('security', 'not authorized', err);
log.info('loader', 'asset loaded', { name, url });

// filtered since security's log level ERROR is greater than INFO
log.info('security', 'login successful');

// filtered since system's log level is turned OFF
log.error('system', 'eject the warp core', error);

// update log levels
log.init({ loader: 'ERROR', system: 'INFO' });

console statements from the "Initialization" and "Use" sections as displayed by Chrome's console

About

Created by Ray Martone.