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

lightweight logging which provides level based filtering and tagging. Filtering keeps your logs readable and uncluttered while tagging makes them searchable.
Features
- Small footprint, around 400 bytes with 0 dependencies
- JSON configuration
- Filter by level,
ERROR > WARN > INFO
- Filter by tag,
'system' | 'whatever'
- Flexible log callback
- Style terminal output with chalk
- Send JSON to a cloud service like Loggly
- Log strings and objects to the console
- API mirrors
console.log
, logs objects** and supports rest parameters - Works reliably with node or any browser through a bundler
- Includes TypeScript definitions so no need for external
@types
Example
log.error('security', 'not authorized', statusCode);
log.warn('transporter', 'Evil twin detected!');
Install
npm install missionlog
Initialize
Tags typically refer to a subsystem or component like 'security'
or FooBar.name
.When missionlog is initialized, tags can be assigned a level. When a message's level is greater than or equal to its tag
's assigned level, missionlog executes a callkack. This simple and elegant approach to logging is incredibly flexible. For example, with missionlog you can seamlessly migrate from console
logging to a sophisticated cloud service with minimal impact!
// var log = require('missionlog').log;
improt { log } from 'missionlog';
/**
* init
* @param config JSON object which assigns tags levels. If uninitialized,
* a tag's level defaults to INFO where ERROR > WARN > INFO.
* @param callback? supports logging whatever way works best for you
* @return {Log} supports chaining
*/
log.init(
{ loader: 'INFO', security: 'ERROR', system: 'OFF' },
(level, tag, msg, params) => {
const prefix = `${level}: [${tag}] `;
switch(level) {
case 'ERROR':
console.error(prefix, msg, ...params);
break;
case 'WARN':
console.warn(prefix, msg, ...params);
break;
case 'INFO':
console.info(prefix, msg, ...params);
break;
}
});
Usage
// filtered since security's log level ERROR is greater than INFO
log.info('security', 'login successful');
// filtered since system's level is OFF
log.error('system', 'eject the warp core', error);
// updates tag levels
log.init({ loader: 'ERROR', system: 'INFO' });