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