]>
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')) |
f1dae018 | 11 | const label = config.get('webserver.host') + ':' + config.get('webserver.port') |
320d6275 C |
12 | |
13 | // Create the directory if it does not exist | |
14 | mkdirp.sync(logDir) | |
15 | ||
f0f5567b | 16 | const logger = new winston.Logger({ |
9f10b292 C |
17 | transports: [ |
18 | new winston.transports.File({ | |
19 | level: 'debug', | |
20 | filename: path.join(logDir, 'all-logs.log'), | |
21 | handleExceptions: true, | |
22 | json: true, | |
23 | maxsize: 5242880, | |
24 | maxFiles: 5, | |
25 | colorize: false | |
26 | }), | |
27 | new winston.transports.Console({ | |
28 | level: 'debug', | |
f1dae018 | 29 | label: label, |
9f10b292 C |
30 | handleExceptions: true, |
31 | humanReadableUnhandledException: true, | |
32 | json: false, | |
33 | colorize: true | |
34 | }) | |
35 | ], | |
36 | exitOnError: true | |
37 | }) | |
8c308c2b | 38 | |
9f10b292 C |
39 | logger.stream = { |
40 | write: function (message, encoding) { | |
41 | logger.info(message) | |
8c308c2b | 42 | } |
9f10b292 | 43 | } |
c45f7f84 | 44 | |
9f10b292 | 45 | // --------------------------------------------------------------------------- |
c45f7f84 | 46 | |
9f10b292 | 47 | module.exports = logger |