]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/logger.ts
Misc cleanup
[github/Chocobozzz/PeerTube.git] / server / helpers / logger.ts
1 // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
2 import * as mkdirp from 'mkdirp'
3 import * as path from 'path'
4 import * as winston from 'winston'
5 import { CONFIG } from '../initializers/constants'
6
7 const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
8
9 // Create the directory if it does not exist
10 mkdirp.sync(CONFIG.STORAGE.LOG_DIR)
11
12 const logger = new winston.Logger({
13 transports: [
14 new winston.transports.File({
15 level: 'debug',
16 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'all-logs.log'),
17 handleExceptions: true,
18 json: true,
19 maxsize: 5242880,
20 maxFiles: 5,
21 colorize: false,
22 prettyPrint: true
23 }),
24 new winston.transports.Console({
25 level: 'debug',
26 label: label,
27 handleExceptions: true,
28 humanReadableUnhandledException: true,
29 json: false,
30 colorize: true,
31 prettyPrint: true
32 })
33 ],
34 exitOnError: true
35 })
36
37 // ---------------------------------------------------------------------------
38
39 export { logger }