All Projects → rmartone → missionlog

rmartone / missionlog

Licence: MIT license
🚀 lightweight logging • supports level based filtering and tagging • weighs in at around 500 bytes

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to missionlog

sprout
Golang logging library supporting log retrieval.
Stars: ✭ 85 (+347.37%)
Mutual labels:  log, logger
l
Cross-platform html/io [L]ogger with simple API.
Stars: ✭ 26 (+36.84%)
Mutual labels:  log, logger
clue
a extremely high performance log library for android. 高性能的Android日志库
Stars: ✭ 27 (+42.11%)
Mutual labels:  log, logger
LogDNA-Android-Client
Android client for LogDNA
Stars: ✭ 22 (+15.79%)
Mutual labels:  log, logger
log
PSR-3 compatible logger
Stars: ✭ 32 (+68.42%)
Mutual labels:  log, logger
JJSwiftLog
Swift log library for all platform
Stars: ✭ 51 (+168.42%)
Mutual labels:  log, logger
vagas
🤝 Venha fazer parte do nosso time
Stars: ✭ 15 (-21.05%)
Mutual labels:  front-end, backend
Awesome Web You Should Know
🌎awesome web you should know
Stars: ✭ 154 (+710.53%)
Mutual labels:  front-end, backend
guzzle-log-middleware
A Guzzle middleware to log request and responses automatically
Stars: ✭ 61 (+221.05%)
Mutual labels:  log, logger
GoogleCloudLogging
Swift (Darwin) library for logging application events in Google Cloud.
Stars: ✭ 24 (+26.32%)
Mutual labels:  log, logger
ng-logger
Angular logger service
Stars: ✭ 65 (+242.11%)
Mutual labels:  log, logger
react-native-log-ios
React Native iOS standalone logger
Stars: ✭ 37 (+94.74%)
Mutual labels:  log, logger
log
Aplus Framework Log Library
Stars: ✭ 14 (-26.32%)
Mutual labels:  log, logger
ng2-logger
Isomorphic logger for Browser and NodeJS, ( typescript / javascript ) apps
Stars: ✭ 61 (+221.05%)
Mutual labels:  isomorphic, logger
datalogger
DataLogger foi projetado para ser uma biblioteca simples de log com suporte a vários providers.
Stars: ✭ 46 (+142.11%)
Mutual labels:  log, logger
log
A simple to use log system, minimalist but with features for debugging and differentiation of messages
Stars: ✭ 21 (+10.53%)
Mutual labels:  log, logger
TIGER
implement a full compiler based on c++ 11
Stars: ✭ 17 (-10.53%)
Mutual labels:  front-end, backend
Dev Practice
Practice your skills with these ideas.
Stars: ✭ 1,127 (+5831.58%)
Mutual labels:  front-end, backend
apollo-log
A logging extension for the Apollo GraphQL Server
Stars: ✭ 64 (+236.84%)
Mutual labels:  log, logger
webpack-log
A logger for the Webpack ecosystem
Stars: ✭ 18 (-5.26%)
Mutual labels:  log, logger

missionlog NPM version Coverage Status

Lightweight logger with an easy configuration. Supports level based filtering and tagging that keeps your logs readable and uncluttered!

Features

  • Small footprint, around 500 bytes
  • Filter by level, ERROR > WARN > INFO > TRACE > DEBUG
  • Filter by tag, 'security' | 'anything'
  • Log callback is extensible from console to cloud
    • Style terminal output with chalk and log to the console
    • Send JSON to a cloud service like Loggly
  • API mirrors console, logs objects and supports rest parameters
  • Works reliably with node or any browser
  • Includes TypeScript definitions so no need for external @types

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. A message is logged when its level is greater than or equal to its tag's assigned level.

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

// handler which does the logging to the console or anything
const logger = {
  [LogLevel.ERROR]: (tag, msg, params) => console.error(`[${chalk.red(tag)}]`, msg, ...params),
  [LogLevel.WARN]: (tag, msg, params) => console.warn(`[${chalk.yellow(tag)}]`, msg, ...params),
  [LogLevel.INFO]: (tag, msg, params) => console.log(`[${chalk.brightGreen(tag)}]`, msg, ...params),
  [LogLevel.TRACE]: (tag, msg, params) => console.log(`[${chalk.cyan(tag)}]`, msg, ...params),
  [LogLevel.DEBUG]: (tag, msg, params) => console.log(`[${chalk.magenta(tag)}]`, msg, ...params),
} as Record<LogLevel, (tag: string, msg: unknown, params: unknown[]) => void>;

/**
 * initialize missionlog
 * @param config JSON which assigns tags levels. An uninitialized,
 *    tag's level defaults to DEBUG.
 * @param callback? handle logging whichever way works best for you
 */
log.init({ transporter: 'INFO', security: 'ERROR', system: 'OFF' }, (level, tag, msg, params) => {
  logger[level as keyof typeof logger](tag, msg, params);
});

Usage

import { log, tag } from 'missionlog';

// the imported value "tag" is populated with YOUR tags!
log.error(tag.security, 'not authorized', statusCode);

// but if you prefer simply use strings
log.warn('transporter', 'Evil twin detected!');

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

// trace
log.trace(tag.system, 'entering engine room');

// debug
log.debug(tag.system, { warpFactor, starDate });

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

// updates tag levels on the fly
log.init({ loader: 'ERROR', system: 'INFO' });

// disable logging by clearing the callback
log.init();

Advanced Usage

Create an instance with its own tags and callback.

import { Log, tag } from 'missionlog';

const myLog = new Log().init(
  { loader: 'INFO', security: 'ERROR' },
  (level, tag, msg, params) => {
    console.log(`${level}: [${tag}] `, msg, ...params);
});

myLog.info(tag.security, 'login successful');
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].