GithubHelp home page GithubHelp logo

nshimiye / captains-log Goto Github PK

View Code? Open in Web Editor NEW

This project forked from balderdashy/captains-log

0.0 2.0 0.0 533 KB

Lightweight logger with a simple pass-through configuration for use with fancier logging libraries. Used by the Sails framework. Optional support for colorized output, custom prefixes, and log levels (using npm's logging conventions.)

License: MIT License

JavaScript 100.00%

captains-log's Introduction

captains-log

Lightweight logger with a simple pass-through configuration for use with fancier logging libraries. Used by the Sails framework. Optional support for colorized output, custom prefixes, and log levels (using npm's logging conventions.)

Installation

$ npm install captains-log

Usage

var log = require('captains-log')();

log('hi');
Logging at a particular level

By default, if you just call log(), captains-log will write your log output at the "debug" log level. You can achieve the same effect by writing log.debug().

IMPORTANT NOTE: npm calls this level log.http(), but we call it debug. If you use log(), the logger sees this as a call to log.debug())

Here are all of the log-level-specific methods which are available in captains-log out of the box:

log.silly();

log.verbose();

log.info();

log.debug()

log.warn();

log.error();

Configuring a custom logger

To use a different library, overrides.custom must already be instantiated and ready to go with (at minimum) an n-ary .debug() method.

Implementing the simplest possible override
var log = require('captains-log')({ custom: customLogger });

log('hello', 'world');
// yields => "Hello world"

This assumes customLogger works as follows:

customLogger.debug()
customLogger.debug('blah')
customLogger.debug('blah', 'foo')
customLogger.debug('blah', 'foo', {bar: 'baz'})
customLogger.debug('blah', 'foo', {bar: 'baz'}, ['a', 3], 2, false);
// etc.

For example:

var customLogger = console.log.bind(console);
Using Winston

Formerly, this module encapsulated winston, a popular logger by @indexzero and the gals/guys over at Nodejitsu. Recently, we made Winston optional to make captains-log as lightweight as possible and reduce the number of npm installs and require()s necessary for its usage in other modules.

But Winston is awesome! And it's a great fit for many apps, giving you granular control over how log output is handled, including sending emails, logging to multiple transports, and other production-time concerns.

To use boot up a captains-log that writes to Winston, do the following:

var log = require('captains-log')({
  custom: new (require('winston').Logger)({
    levels     : ...,
    transports : ...
  })
});

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.