diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-27 14:32:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-27 15:12:22 +0200 |
commit | 41fb13c330de629df2d23379209e79c7af0f2e9a (patch) | |
tree | 73bc5a90566406b3910f142beae2a879c1e4265d /server/helpers/logger.ts | |
parent | 40e7ed0714f96c01e16de3ac971a4b28116294e1 (diff) | |
download | PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.gz PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.tar.zst PeerTube-41fb13c330de629df2d23379209e79c7af0f2e9a.zip |
esModuleInterop to true
Diffstat (limited to 'server/helpers/logger.ts')
-rw-r--r-- | server/helpers/logger.ts | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 20c3c3edb..4bd00e503 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ | 1 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ |
2 | import { mkdirpSync, stat } from 'fs-extra' | 2 | import { mkdirpSync, stat } from 'fs-extra' |
3 | import { omit } from 'lodash' | 3 | import { omit } from 'lodash' |
4 | import * as path from 'path' | 4 | import { join } from 'path' |
5 | import { format as sqlFormat } from 'sql-formatter' | 5 | import { format as sqlFormat } from 'sql-formatter' |
6 | import * as winston from 'winston' | 6 | import { createLogger, format, transports } from 'winston' |
7 | import { FileTransportOptions } from 'winston/lib/winston/transports' | 7 | import { FileTransportOptions } from 'winston/lib/winston/transports' |
8 | import { CONFIG } from '../initializers/config' | 8 | import { CONFIG } from '../initializers/config' |
9 | import { LOG_FILENAME } from '../initializers/constants' | 9 | import { LOG_FILENAME } from '../initializers/constants' |
@@ -47,7 +47,7 @@ function getLoggerReplacer () { | |||
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | const consoleLoggerFormat = winston.format.printf(info => { | 50 | const consoleLoggerFormat = format.printf(info => { |
51 | const toOmit = [ 'label', 'timestamp', 'level', 'message', 'sql', 'tags' ] | 51 | const toOmit = [ 'label', 'timestamp', 'level', 'message', 'sql', 'tags' ] |
52 | 52 | ||
53 | const obj = omit(info, ...toOmit) | 53 | const obj = omit(info, ...toOmit) |
@@ -71,24 +71,24 @@ const consoleLoggerFormat = winston.format.printf(info => { | |||
71 | return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` | 71 | return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` |
72 | }) | 72 | }) |
73 | 73 | ||
74 | const jsonLoggerFormat = winston.format.printf(info => { | 74 | const jsonLoggerFormat = format.printf(info => { |
75 | return JSON.stringify(info, getLoggerReplacer()) | 75 | return JSON.stringify(info, getLoggerReplacer()) |
76 | }) | 76 | }) |
77 | 77 | ||
78 | const timestampFormatter = winston.format.timestamp({ | 78 | const timestampFormatter = format.timestamp({ |
79 | format: 'YYYY-MM-DD HH:mm:ss.SSS' | 79 | format: 'YYYY-MM-DD HH:mm:ss.SSS' |
80 | }) | 80 | }) |
81 | const labelFormatter = (suffix?: string) => { | 81 | const labelFormatter = (suffix?: string) => { |
82 | return winston.format.label({ | 82 | return format.label({ |
83 | label: suffix ? `${label} ${suffix}` : label | 83 | label: suffix ? `${label} ${suffix}` : label |
84 | }) | 84 | }) |
85 | } | 85 | } |
86 | 86 | ||
87 | const fileLoggerOptions: FileTransportOptions = { | 87 | const fileLoggerOptions: FileTransportOptions = { |
88 | filename: path.join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME), | 88 | filename: join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME), |
89 | handleExceptions: true, | 89 | handleExceptions: true, |
90 | format: winston.format.combine( | 90 | format: format.combine( |
91 | winston.format.timestamp(), | 91 | format.timestamp(), |
92 | jsonLoggerFormat | 92 | jsonLoggerFormat |
93 | ) | 93 | ) |
94 | } | 94 | } |
@@ -101,19 +101,19 @@ if (CONFIG.LOG.ROTATION.ENABLED) { | |||
101 | const logger = buildLogger() | 101 | const logger = buildLogger() |
102 | 102 | ||
103 | function buildLogger (labelSuffix?: string) { | 103 | function buildLogger (labelSuffix?: string) { |
104 | return winston.createLogger({ | 104 | return createLogger({ |
105 | level: CONFIG.LOG.LEVEL, | 105 | level: CONFIG.LOG.LEVEL, |
106 | format: winston.format.combine( | 106 | format: format.combine( |
107 | labelFormatter(labelSuffix), | 107 | labelFormatter(labelSuffix), |
108 | winston.format.splat() | 108 | format.splat() |
109 | ), | 109 | ), |
110 | transports: [ | 110 | transports: [ |
111 | new winston.transports.File(fileLoggerOptions), | 111 | new transports.File(fileLoggerOptions), |
112 | new winston.transports.Console({ | 112 | new transports.Console({ |
113 | handleExceptions: true, | 113 | handleExceptions: true, |
114 | format: winston.format.combine( | 114 | format: format.combine( |
115 | timestampFormatter, | 115 | timestampFormatter, |
116 | winston.format.colorize(), | 116 | format.colorize(), |
117 | consoleLoggerFormat | 117 | consoleLoggerFormat |
118 | ) | 118 | ) |
119 | }) | 119 | }) |