Node.js Logging


Is there any library which will help me to handle logging in my Node.Js application? All I want to do is, I want to write all logs into a File and also I need an options like rolling out the file after certain size or date.

I have incorporated log4js im trying to keep all the configuration details in one file and use only the methods in other application files for ease of maintenance. But it doesnt work as expected. Here is what I'm trying to do

var log4js = require('log4js'); 
log4js.addAppender(log4js.appenders.file('test.log'), 'test');
var logger = log4js.getLogger('test');

var traceLogger = function (message) {

var errorLogger = function (message) {

exports.trace = traceLogger;
exports.error = errorLogger;

I have included this file in other files and tried

log.error ("Hello Error Message");

But it is not working. Is there anything wrong in this ?

10/6/2015 3:37:50 PM

Accepted Answer

Winston is a pretty good logging library. You can write logs out to a file using it.

Code would look something like:

var winston = require('winston');

var logger = new (winston.Logger)({
  transports: [
    new (winston.transports.Console)({ json: false, timestamp: true }),
    new winston.transports.File({ filename: __dirname + '/debug.log', json: false })
  exceptionHandlers: [
    new (winston.transports.Console)({ json: false, timestamp: true }),
    new winston.transports.File({ filename: __dirname + '/exceptions.log', json: false })
  exitOnError: false

module.exports = logger;

You can then use this like:

var logger = require('./log');'log to file');
4/10/2013 5:28:41 PM

Scribe.JS Lightweight Logger

I have looked through many loggers, and I wasn't able to find a lightweight solution - so I decided to make a simple solution that is posted on github.

  • Saves the file which are organized by user, date, and level
  • Gives you a pretty output (we all love that)
  • Easy-to-use HTML interface

I hope this helps you out.

Online Demo

Secure Web Access to Logs


Prints Pretty Text to Console Too!


Web Access



Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow