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