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.ts32
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/
2import { mkdirpSync, stat } from 'fs-extra' 2import { mkdirpSync, stat } from 'fs-extra'
3import { omit } from 'lodash' 3import { omit } from 'lodash'
4import * as path from 'path' 4import { join } from 'path'
5import { format as sqlFormat } from 'sql-formatter' 5import { format as sqlFormat } from 'sql-formatter'
6import * as winston from 'winston' 6import { createLogger, format, transports } from 'winston'
7import { FileTransportOptions } from 'winston/lib/winston/transports' 7import { FileTransportOptions } from 'winston/lib/winston/transports'
8import { CONFIG } from '../initializers/config' 8import { CONFIG } from '../initializers/config'
9import { LOG_FILENAME } from '../initializers/constants' 9import { LOG_FILENAME } from '../initializers/constants'
@@ -47,7 +47,7 @@ function getLoggerReplacer () {
47 } 47 }
48} 48}
49 49
50const consoleLoggerFormat = winston.format.printf(info => { 50const 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
74const jsonLoggerFormat = winston.format.printf(info => { 74const jsonLoggerFormat = format.printf(info => {
75 return JSON.stringify(info, getLoggerReplacer()) 75 return JSON.stringify(info, getLoggerReplacer())
76}) 76})
77 77
78const timestampFormatter = winston.format.timestamp({ 78const timestampFormatter = format.timestamp({
79 format: 'YYYY-MM-DD HH:mm:ss.SSS' 79 format: 'YYYY-MM-DD HH:mm:ss.SSS'
80}) 80})
81const labelFormatter = (suffix?: string) => { 81const 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
87const fileLoggerOptions: FileTransportOptions = { 87const 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) {
101const logger = buildLogger() 101const logger = buildLogger()
102 102
103function buildLogger (labelSuffix?: string) { 103function 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 })