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