Giter Club home page Giter Club logo

logi's Introduction

logi

Logi is a simple logger for Node.js

First, create a logger factory that defines the common settings:

// For an example, these are the default options that will be used if they are not specified:
var options = {}
// define the log levels
options.levels = {trace: 100, debug:90, info:80, notice:70, warn:50, warning:50, error:30, critical:20, fatal:10};
// output all levels
options.threshold = 100;
//output error, critical, and fatal to stderr
options.errorThreshold = 30;
// make the logger print a shorter path relative to the main app
options.showAbsolutePath = false;

var logi = require('logi')(options);

To log to a file specify the path to the file as options.out. Any directory in the path must exist. By default any output will be sent to stdout. Directing the output to any other target is possible by specifying a writable stream.

options.out = 'app.log';

Using the factory, a logger instance can be created for each module:

var logger = logi.create(module);

var firstName = 'John';
logger.debug('firstName=%s', firstName);

This will output something like this to the stdout:

[2014-02-07T04:35:23.534Z] [DEBUG] [example.js] - firstName=John

All logger instances created from the same factory shares the common settings of the log levels and threshold.

Appenders can be defined in several ways:

  1. String value will make logi automatically create a file appender with default settings. options.out = '/path/to/log/file';

  2. An array of objects will be directly treated as an appender object, therefore the object must implement the correct methods.

    // Logs to both file and stdout options.out = [ logi.appenders.file('/path/to/log/file'), logi.appenders.stdout, ];

    // Use custom appender var myCustomAppender = new myCustomAppender(); options.out = [ myCustomAppender ];

    // Logs to nowhere options.out = [];

  3. Use a simple object to define the use of one or more built-in appenders. The key is the name of the built in appender and the value is the options passed to the appender.

    out = { file : { path : '/path/to/log/file', maxSize : 1024, //size in byte

    } }

The parameters out and err behave exactly the same. If out is not specified, stdout is used If err is not specified, stderr is used

logi's People

Contributors

alvinsw avatar

Watchers

James Cloos avatar

Forkers

ternaustralia

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.