sp-logger

Combines "coloured" and "log.js" for super simple pretty logging.

npm install sp-logger
2 downloads in the last week
48 downloads in the last month

It is a wrapper around logToFile logger, which provides dfferent logs levels, rotation, compression and colored logs on console.

To install sp-logger, use [npm]:

$ npm install sp-logger

Below is the list of other configurable options.

var options = { enable: ["error", "warn", "info", "debug", "stdout", "stderr"], fileName: "node.log", directory: "../log", writeDelay: 200, bufferSize: 4096, fileMaxSize: 1024 1024 10, maxBackupFileNumber: 10, gzipBackupFile: false, compressionLevel: 3, verbose: true

Example


var log = require("sp-logger");

Minimum options required to use it are enable, directory and fileName;
var logger = log.create({
    enable: ["error", "warn", "info", "debug", "stdout", "stderr"],
    directory:"./", fileName:"node_test.log"
});

Error and stream (stdout, stderr) logging

Outputs "Wed Aug 29 2012 16:15:56 GMT+0530 (IST) ERROR: This goes out to error.log

    logger.error("This goes out to error.log");

Outputs "Wed Aug 29 2012 16:15:56 GMT+0530 (IST) ERROR: This goes out to stderr"

    logger.stderr("This goes out to stderr");

Outputs "Wed Aug 29 2012 16:15:56 GMT+0530 (IST) OUT: This goes out to stdout"

    logger.stdout("This goes out to stdout");

You could do chaining as well, though it may not be needed.

logger
    .warn("This goes out to warn.log") 
    .info("This goes out to info.log")
    .debug("This goes out to debug.log")

Enabling/disabling logger types.

logger
    .disable("error")
    .error("This goes out to error.log") // No output
    .enable("error")
    .error("This goes out to error.log"); // Outputs "ERROR: This goes out to error.log"

Ideal way to use in application and make is available to all js files.

console.logger = logger;

Then use anywhere in you app as below.

console.logger.error("This goes out to error.log");
console.logger.warn("This goes out to warn.log");
console.logger.disable("error");
npm loves you