// Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
import { mkdirpSync } from 'fs-extra'
+import { omit } from 'lodash'
import * as path from 'path'
+import { format as sqlFormat } from 'sql-formatter'
import * as winston from 'winston'
import { FileTransportOptions } from 'winston/lib/winston/transports'
import { CONFIG } from '../initializers/config'
-import { omit } from 'lodash'
import { LOG_FILENAME } from '../initializers/constants'
const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
// Thanks: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#Examples
return (key: string, value: any) => {
+ if (key === 'cert') return 'Replaced by the logger to avoid large log message'
+
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) return
}
const consoleLoggerFormat = winston.format.printf(info => {
- const obj = omit(info, 'label', 'timestamp', 'level', 'message')
+ const toOmit = [ 'label', 'timestamp', 'level', 'message' ]
+ if (CONFIG.LOG.PRETTIFY_SQL) toOmit.push('sql')
+
+ const obj = omit(info, ...toOmit)
let additionalInfos = JSON.stringify(obj, getLoggerReplacer(), 2)
if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = ''
else additionalInfos = ' ' + additionalInfos
+ if (CONFIG.LOG.PRETTIFY_SQL && info.sql) {
+ additionalInfos += '\n' + sqlFormat(info.sql, {
+ language: 'sql',
+ ident: ' '
+ })
+ }
+
return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}`
})