diff options
Diffstat (limited to 'helpers/logger.js')
-rw-r--r-- | helpers/logger.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/helpers/logger.js b/helpers/logger.js new file mode 100644 index 000000000..850af10cb --- /dev/null +++ b/helpers/logger.js | |||
@@ -0,0 +1,40 @@ | |||
1 | ;(function () { | ||
2 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ | ||
3 | 'use strict' | ||
4 | |||
5 | var config = require('config') | ||
6 | var winston = require('winston') | ||
7 | |||
8 | var logDir = __dirname + '/../' + config.get('storage.logs') | ||
9 | |||
10 | winston.emitErrs = true | ||
11 | |||
12 | var logger = new winston.Logger({ | ||
13 | transports: [ | ||
14 | new winston.transports.File({ | ||
15 | level: 'debug', | ||
16 | filename: logDir + '/all-logs.log', | ||
17 | handleExceptions: true, | ||
18 | json: true, | ||
19 | maxsize: 5242880, | ||
20 | maxFiles: 5, | ||
21 | colorize: false | ||
22 | }), | ||
23 | new winston.transports.Console({ | ||
24 | level: 'debug', | ||
25 | handleExceptions: true, | ||
26 | humanReadableUnhandledException: true, | ||
27 | json: false, | ||
28 | colorize: true | ||
29 | }) | ||
30 | ], | ||
31 | exitOnError: true | ||
32 | }) | ||
33 | |||
34 | module.exports = logger | ||
35 | module.exports.stream = { | ||
36 | write: function (message, encoding) { | ||
37 | logger.info(message) | ||
38 | } | ||
39 | } | ||
40 | })() | ||