Skip to content

Commit

Permalink
Logging with winston
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandt Heisey committed Apr 8, 2015
1 parent 2b63e30 commit d1777f0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 25 deletions.
90 changes: 66 additions & 24 deletions config/log.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,71 @@
console.log('Loading... ', __filename);

var winston = require('winston');
/**
* Logger configuration
*
* Configure the log level for your app, as well as the transport
* (Underneath the covers, Sails uses Winston for logging, which
* allows for some pretty neat custom transports/adapters for log messages)
*
* For more information on the Sails logger, check out:
* http://sailsjs.org/#documentation
*/
* Logger configuration
*
* Configure the log level for your app, as well as the transport
* (Underneath the covers, Sails uses Winston for logging, which
* allows for some pretty neat custom transports/adapters for log messages)
*
* For more information on the Sails logger, check out:
* http://sailsjs.org/#documentation
*/
/*
Winston log levels are flipped from sails log levels, so using the log_level array makes it behave as expected in the sails documentation
*/

var log_levels = {
silent: 6,
error: 5,
warn: 4,
debug: 3,
info: 2,
verbose: 1,
silly: 0
};

module.exports = {
var transports = [
new (winston.transports.File)(
/*This Transport controls what is written to the log file*/
{
level: 'verbose',
name: 'written.log',
silent: false,
colorize: false,
timestamp: true,
filename: "application.log",
maxsize: 500000,
maxFiles: 5,
json: false,
handleExceptions: false
}
),
new (winston.transports.Console)(
/*This Transport is required to get console output, regardless of sails log level
* output will be the lesser of sails log level and the transport level if they aren't equal
* accordingly, transport log level shoul always be equal or lower than sails log level for readability's sake
*/
{
level: 'silly',
name: 'console.log',
silent: false,
colorize: true,
timestamp: true,
json: false,
handleExceptions: false
}
)
];

// Valid `level` configs:
// i.e. the minimum log level to capture with sails.log.*()
//
// 'error' : Display calls to `.error()`
// 'warn' : Display calls from `.error()` to `.warn()`
// 'debug' : Display calls from `.error()`, `.warn()` to `.debug()`
// 'info' : Display calls from `.error()`, `.warn()`, `.debug()` to `.info()`
// 'verbose': Display calls from `.error()`, `.warn()`, `.debug()`, `.info()` to `.verbose()`
//
log: {
level: 'info'
}
var logger = new (winston.Logger)({
exitOnError: false,
transports: transports,
levels: log_levels
});

};
/* Don't forget to set the sails logging level to a higher or equal level to what you want in the logs */
module.exports.log = {
level: 'silly',
colors: false, // To get clean logs without prefixes or color codings
custom: logger
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"timepicker": "jonthornton/jquery-timepicker#1.2.15",
"uglifyify": "^3.0.1",
"underscore": "^1.8.2",
"validator": "3.4.0"
"validator": "3.4.0",
"winston": "^0.9.0"
},
"devDependencies": {
"casper-chai": "^0.2.1",
Expand Down

0 comments on commit d1777f0

Please sign in to comment.