aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/logger.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/logger.ts')
-rw-r--r--server/helpers/logger.ts60
1 files changed, 48 insertions, 12 deletions
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts
index 2676133db..6a02f680a 100644
--- a/server/helpers/logger.ts
+++ b/server/helpers/logger.ts
@@ -9,26 +9,57 @@ const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
9// Create the directory if it does not exist 9// Create the directory if it does not exist
10mkdirp.sync(CONFIG.STORAGE.LOG_DIR) 10mkdirp.sync(CONFIG.STORAGE.LOG_DIR)
11 11
12const logger = new winston.Logger({ 12// Use object for better performances (~ O(1))
13const excludedKeys = {
14 level: true,
15 message: true,
16 splat: true,
17 timestamp: true,
18 label: true
19}
20function keysExcluder (key, value) {
21 return excludedKeys[key] === true ? undefined : value
22}
23
24const loggerFormat = winston.format.printf((info) => {
25 let additionalInfos = JSON.stringify(info, keysExcluder, 2)
26 if (additionalInfos === '{}') additionalInfos = ''
27
28 return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message} ${additionalInfos}`
29})
30
31const timestampFormatter = winston.format.timestamp({
32 format: 'YYYY-MM-dd HH:mm:ss.SSS'
33})
34const labelFormatter = winston.format.label({
35 label
36})
37
38const logger = new winston.createLogger({
39 level: CONFIG.LOG.LEVEL,
13 transports: [ 40 transports: [
14 new winston.transports.File({ 41 new winston.transports.File({
15 level: 'debug', 42 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'),
16 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'all-logs.log'),
17 handleExceptions: true, 43 handleExceptions: true,
18 json: true,
19 maxsize: 5242880, 44 maxsize: 5242880,
20 maxFiles: 5, 45 maxFiles: 5,
21 colorize: false, 46 format: winston.format.combine(
22 prettyPrint: true 47 timestampFormatter,
48 labelFormatter,
49 winston.format.splat(),
50 winston.format.json()
51 )
23 }), 52 }),
24 new winston.transports.Console({ 53 new winston.transports.Console({
25 level: 'debug',
26 label: label,
27 handleExceptions: true, 54 handleExceptions: true,
28 humanReadableUnhandledException: true, 55 humanReadableUnhandledException: true,
29 json: false, 56 format: winston.format.combine(
30 colorize: true, 57 timestampFormatter,
31 prettyPrint: true 58 winston.format.splat(),
59 labelFormatter,
60 winston.format.colorize(),
61 loggerFormat
62 )
32 }) 63 })
33 ], 64 ],
34 exitOnError: true 65 exitOnError: true
@@ -36,4 +67,9 @@ const logger = new winston.Logger({
36 67
37// --------------------------------------------------------------------------- 68// ---------------------------------------------------------------------------
38 69
39export { logger } 70export {
71 timestampFormatter,
72 labelFormatter,
73 loggerFormat,
74 logger
75}