Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oniyi-logger

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oniyi-logger

A simple loglevel and label wrapper around process.stdout

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NPM info

A simple loglevel and label wrapper around process.stdout

Install

$ npm install --save oniyi-logger

Usage

all log functions work similar to console.log() and can take multiple arguments in a printf()-like way. Note that the debug() method is a noop per default. To enable debug() logging, you must use a labled logger, and list the label in the NODE_DEBUG environment variable. NODE_DEBUG must be a comma, or space separated list

var fs = require('fs');

// standard use-case, will log to process.stdout
var logger = require('oniyi-logger')('my-awesome-module');

logger.info('my %s message', 'info');
// INFO [my-awesome-module] my info message
logger.debug('my debug message');
// Does not log anything
logger.warn('my warn message');
// WARN [my-awesome-module] my warn message
logger.error('my error message');
// ERROR [my-awesome-module] my error message


// log to a file
var labeledFileLog = require('oniyi-logger')('file', {sink: fs.createWriteStream('file.log, {flags: 'a'}')});

labeledFileLog.info('my info message');
// writes "INFO [file] my info message" to file.log
labeledFileLog.debug('my debug message');
// writes does not write anything to file.log
labeledFileLog.warn('my warn message');
// writes "WARN [file] my warn message" to file.log
labeledFileLog.error('my error message');
// writes "ERROR [file] my wrror message" to file.log

You can use nested lables to controle debug messages with finer granularity.

so with process.env.NODE_DEBUG = 'foo:bar', you get this:

const oniyiLogger = require('oniyi-logger');
const fooLogger = oniyiLogger('foo');
const barLogger = oniyiLogger('foo:bar');

fooLogger.debug('my debug message');
// Does not log anything

barLogger.debug('my debug message');
// DEBUG [foo:bar] my debug message

and with process.env.NODE_DEBUG = 'foo:*', you get this:

const oniyiLogger = require('oniyi-logger');
const fooLogger = oniyiLogger('foo');
const barLogger = oniyiLogger('foo:bar');

fooLogger.debug('my debug message');
// DEBUG [foo] my debug message

barLogger.debug('my debug message');
// DEBUG [foo:bar] my debug message

License

Apache 2.0 © Benjamin Kroeger

Keywords

FAQs

Package last updated on 07 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc