]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/logger.js
Better tests for a better world
[github/Chocobozzz/PeerTube.git] / server / helpers / logger.js
CommitLineData
9f10b292
C
1// Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
2'use strict'
8c308c2b 3
f0f5567b 4const config = require('config')
320d6275 5const mkdirp = require('mkdirp')
f0f5567b
C
6const path = require('path')
7const winston = require('winston')
9f10b292 8winston.emitErrs = true
8c308c2b 9
f0f5567b 10const logDir = path.join(__dirname, '..', '..', config.get('storage.logs'))
320d6275
C
11
12// Create the directory if it does not exist
13mkdirp.sync(logDir)
14
f0f5567b 15const 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
37logger.stream = {
38 write: function (message, encoding) {
39 logger.info(message)
8c308c2b 40 }
9f10b292 41}
c45f7f84 42
9f10b292 43// ---------------------------------------------------------------------------
c45f7f84 44
9f10b292 45module.exports = logger