diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/logger.ts | 51 |
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 => { | |||
54 | const timestampFormatter = winston.format.timestamp({ | 54 | const timestampFormatter = winston.format.timestamp({ |
55 | format: 'YYYY-MM-DD HH:mm:ss.SSS' | 55 | format: 'YYYY-MM-DD HH:mm:ss.SSS' |
56 | }) | 56 | }) |
57 | const labelFormatter = winston.format.label({ | 57 | const labelFormatter = (suffix?: string) => { |
58 | label | 58 | return winston.format.label({ |
59 | }) | 59 | label: suffix ? `${label} ${suffix}` : label |
60 | }) | ||
61 | } | ||
60 | 62 | ||
61 | const fileLoggerOptions: FileTransportOptions = { | 63 | const 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 | ||
75 | const logger = winston.createLogger({ | 77 | const logger = buildLogger() |
76 | level: CONFIG.LOG.LEVEL, | 78 | |
77 | format: winston.format.combine( | 79 | function 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 | ||
95 | function bunyanLogFactory (level: string) { | 101 | function bunyanLogFactory (level: string) { |
96 | return function () { | 102 | return function () { |
@@ -123,6 +129,7 @@ const bunyanLogger = { | |||
123 | // --------------------------------------------------------------------------- | 129 | // --------------------------------------------------------------------------- |
124 | 130 | ||
125 | export { | 131 | export { |
132 | buildLogger, | ||
126 | timestampFormatter, | 133 | timestampFormatter, |
127 | labelFormatter, | 134 | labelFormatter, |
128 | consoleLoggerFormat, | 135 | consoleLoggerFormat, |