Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module now requires passing config as a parameter
- Loading branch information
Showing
3 changed files
with
59 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,63 @@ | ||
var config = require('nconf') | ||
var Loggly = require('winston-loggly').Loggly | ||
var winston = require('winston'); | ||
var loggly = config.get('loggly') | ||
// prepare some custom log levels | ||
var customLevels = { | ||
levels: { | ||
debug: 0, | ||
info: 1, | ||
warning: 2, | ||
error: 3 | ||
}, | ||
colors: { | ||
debug: 'blue', | ||
info: 'green', | ||
warning: 'yellow', | ||
error: 'red' | ||
|
||
module.exports = function (config) { | ||
var loggly = config.get('loggly') | ||
// prepare some custom log levels | ||
var customLevels = { | ||
levels: { | ||
debug: 0, | ||
info: 1, | ||
warning: 2, | ||
error: 3 | ||
}, | ||
colors: { | ||
debug: 'blue', | ||
info: 'green', | ||
warning: 'yellow', | ||
error: 'red' | ||
} | ||
} | ||
} | ||
|
||
var handleExceptions = true | ||
if (config.get('test')) { | ||
handleExceptions = false | ||
} | ||
var transports = [ | ||
// setup console logging | ||
new (winston.transports.Console)({ | ||
var handleExceptions = true | ||
if (config.get('test')) { | ||
handleExceptions = false | ||
} | ||
var transports = [ | ||
// setup console logging | ||
new (winston.transports.Console)({ | ||
level: 'debug', | ||
levels: customLevels.levels, | ||
handleExceptions: handleExceptions, | ||
prettyPrint: true, | ||
colorize: true | ||
}) | ||
] | ||
|
||
|
||
// setup logging to loggly | ||
if (config.get('loggly')) { | ||
transports.push(new winston.transports.Loggly({ | ||
subdomain: 'nisaacson', | ||
inputToken: loggly.inputToken, | ||
handleExceptions: handleExceptions, | ||
level: 'info', | ||
prettyPrint: true, | ||
json: true | ||
// colors: customLevels.colors | ||
})) | ||
} | ||
|
||
// create the logger | ||
var logger = module.exports = new (winston.Logger)({ | ||
level: 'debug', | ||
levels: customLevels.levels, | ||
handleExceptions: handleExceptions, | ||
prettyPrint: true, | ||
colorize: true | ||
handleExceptions: true, | ||
transports: transports, | ||
colors: customLevels.colors | ||
}) | ||
] | ||
|
||
|
||
// setup logging to loggly | ||
if (config.get('loggly')) { | ||
transports.push(new winston.transports.Loggly({ | ||
subdomain: 'nisaacson', | ||
inputToken: loggly.inputToken, | ||
handleExceptions: handleExceptions, | ||
level: 'info', | ||
prettyPrint: true, | ||
json: true | ||
// colors: customLevels.colors | ||
})) | ||
// set the coloring | ||
winston.addColors(customLevels.colors) | ||
return logger | ||
} | ||
|
||
// create the logger | ||
var logger = module.exports = new (winston.Logger)({ | ||
level: 'debug', | ||
levels: customLevels.levels, | ||
handleExceptions: true, | ||
transports: transports, | ||
colors: customLevels.colors | ||
}) | ||
|
||
// set the coloring | ||
winston.addColors(customLevels.colors) | ||
|
||
module.exports = logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters