]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ |
4d4e5cd4 C |
2 | import * as mkdirp from 'mkdirp' |
3 | import * as path from 'path' | |
4 | import * as winston from 'winston' | |
8c308c2b | 5 | |
65fcc311 C |
6 | // Do not use barrel (dependencies issues) |
7 | import { CONFIG } from '../initializers/constants' | |
8c308c2b | 8 | |
65fcc311 | 9 | const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT |
320d6275 C |
10 | |
11 | // Create the directory if it does not exist | |
65fcc311 | 12 | mkdirp.sync(CONFIG.STORAGE.LOG_DIR) |
320d6275 | 13 | |
f0f5567b | 14 | const logger = new winston.Logger({ |
9f10b292 C |
15 | transports: [ |
16 | new winston.transports.File({ | |
17 | level: 'debug', | |
65fcc311 | 18 | filename: path.join(CONFIG.STORAGE.LOG_DIR, 'all-logs.log'), |
9f10b292 C |
19 | handleExceptions: true, |
20 | json: true, | |
21 | maxsize: 5242880, | |
22 | maxFiles: 5, | |
feb4bdfd C |
23 | colorize: false, |
24 | prettyPrint: true | |
9f10b292 C |
25 | }), |
26 | new winston.transports.Console({ | |
27 | level: 'debug', | |
f1dae018 | 28 | label: label, |
9f10b292 C |
29 | handleExceptions: true, |
30 | humanReadableUnhandledException: true, | |
31 | json: false, | |
feb4bdfd C |
32 | colorize: true, |
33 | prettyPrint: true | |
9f10b292 C |
34 | }) |
35 | ], | |
36 | exitOnError: true | |
37 | }) | |
8c308c2b | 38 | |
9f10b292 | 39 | // --------------------------------------------------------------------------- |
c45f7f84 | 40 | |
65fcc311 | 41 | export { logger } |