Archive for the ‘Winston.js’ category

Add some sweet logging to your Javascript/Node.js apps with Winston

March 19th, 2013

If you are looking for a logging solution to your javascript or node.js apps, look no further, enter Winston.  This little tool can write logs from your apps to a file, to the console, or to a database and you can even query the logs with its own built in syntax, how sweet is that?  Anyways, I have included below the code snippets that is needed to get it going, check it out:

//by default, Winston is set to log to console 
var winston = require('winston');

 winston.log('info', 'Hello distributed log files!');'Hello again distributed logs');

//you can change that behavior by doing something like this:
winston.add(winston.transports.File, { filename: 'somefile.log' });

Here is the github repo for further reading if you are considering this tool

Pretty simple, just three lines of code and you are logging, just slap a anywhere you want to see some info and you are good to go, enjoy!!