]>
Commit | Line | Data |
---|---|---|
8c308c2b C |
1 | ;(function () { |
2 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ | |
8c308c2b C |
3 | 'use strict' |
4 | ||
8c308c2b | 5 | var config = require('config') |
b3077e41 | 6 | var path = require('path') |
a1860380 | 7 | var winston = require('winston') |
8c308c2b C |
8 | winston.emitErrs = true |
9 | ||
b3077e41 | 10 | var logDir = path.join(__dirname, '..', config.get('storage.logs')) |
8c308c2b C |
11 | var logger = new winston.Logger({ |
12 | transports: [ | |
13 | new winston.transports.File({ | |
14 | level: 'debug', | |
b3077e41 | 15 | filename: path.join(logDir, 'all-logs.log'), |
8c308c2b C |
16 | handleExceptions: true, |
17 | json: true, | |
18 | maxsize: 5242880, | |
19 | maxFiles: 5, | |
20 | colorize: false | |
21 | }), | |
22 | new winston.transports.Console({ | |
23 | level: 'debug', | |
24 | handleExceptions: true, | |
25 | humanReadableUnhandledException: true, | |
26 | json: false, | |
27 | colorize: true | |
28 | }) | |
29 | ], | |
30 | exitOnError: true | |
31 | }) | |
32 | ||
c45f7f84 | 33 | logger.stream = { |
8c308c2b C |
34 | write: function (message, encoding) { |
35 | logger.info(message) | |
36 | } | |
37 | } | |
c45f7f84 C |
38 | |
39 | // --------------------------------------------------------------------------- | |
40 | ||
41 | module.exports = logger | |
8c308c2b | 42 | })() |