aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-09 09:57:32 +0200
committerChocobozzz <me@florianbigard.com>2020-04-09 09:57:32 +0200
commitbc0d801bb7a0cc503c1637f4a07bb51d68d85608 (patch)
tree6eb486085fb5b536309315b4db06c790acf98ed0 /server/helpers
parent00c228363f0db1d181d546eebb0c7ec3eb487976 (diff)
downloadPeerTube-bc0d801bb7a0cc503c1637f4a07bb51d68d85608.tar.gz
PeerTube-bc0d801bb7a0cc503c1637f4a07bb51d68d85608.tar.zst
PeerTube-bc0d801bb7a0cc503c1637f4a07bb51d68d85608.zip
Refactor plugin helpers factory
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/logger.ts51
1 files changed, 29 insertions, 22 deletions
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts
index b8ae28b3f..9553f70e8 100644
--- a/server/helpers/logger.ts
+++ b/server/helpers/logger.ts
@@ -54,9 +54,11 @@ const jsonLoggerFormat = winston.format.printf(info => {
54const timestampFormatter = winston.format.timestamp({ 54const timestampFormatter = winston.format.timestamp({
55 format: 'YYYY-MM-DD HH:mm:ss.SSS' 55 format: 'YYYY-MM-DD HH:mm:ss.SSS'
56}) 56})
57const labelFormatter = winston.format.label({ 57const labelFormatter = (suffix?: string) => {
58 label 58 return winston.format.label({
59}) 59 label: suffix ? `${label} ${suffix}` : label
60 })
61}
60 62
61const fileLoggerOptions: FileTransportOptions = { 63const fileLoggerOptions: FileTransportOptions = {
62 filename: path.join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME), 64 filename: path.join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME),
@@ -72,25 +74,29 @@ if (CONFIG.LOG.ROTATION.ENABLED) {
72 fileLoggerOptions.maxFiles = CONFIG.LOG.ROTATION.MAX_FILES 74 fileLoggerOptions.maxFiles = CONFIG.LOG.ROTATION.MAX_FILES
73} 75}
74 76
75const logger = winston.createLogger({ 77const logger = buildLogger()
76 level: CONFIG.LOG.LEVEL, 78
77 format: winston.format.combine( 79function buildLogger (labelSuffix?: string) {
78 labelFormatter, 80 return winston.createLogger({
79 winston.format.splat() 81 level: CONFIG.LOG.LEVEL,
80 ), 82 format: winston.format.combine(
81 transports: [ 83 labelFormatter(labelSuffix),
82 new winston.transports.File(fileLoggerOptions), 84 winston.format.splat()
83 new winston.transports.Console({ 85 ),
84 handleExceptions: true, 86 transports: [
85 format: winston.format.combine( 87 new winston.transports.File(fileLoggerOptions),
86 timestampFormatter, 88 new winston.transports.Console({
87 winston.format.colorize(), 89 handleExceptions: true,
88 consoleLoggerFormat 90 format: winston.format.combine(
89 ) 91 timestampFormatter,
90 }) 92 winston.format.colorize(),
91 ], 93 consoleLoggerFormat
92 exitOnError: true 94 )
93}) 95 })
96 ],
97 exitOnError: true
98 })
99}
94 100
95function bunyanLogFactory (level: string) { 101function bunyanLogFactory (level: string) {
96 return function () { 102 return function () {
@@ -123,6 +129,7 @@ const bunyanLogger = {
123// --------------------------------------------------------------------------- 129// ---------------------------------------------------------------------------
124 130
125export { 131export {
132 buildLogger,
126 timestampFormatter, 133 timestampFormatter,
127 labelFormatter, 134 labelFormatter,
128 consoleLoggerFormat, 135 consoleLoggerFormat,