]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/logger.ts
Disable sql prettifier by default
[github/Chocobozzz/PeerTube.git] / server / helpers / logger.ts
index a4bd414274b43da679569a533bef7ed0be5d225f..0548dfd5ba4a6e1e4c4993ee21e95f366df0cf86 100644 (file)
@@ -1,10 +1,11 @@
 // 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
@@ -39,13 +40,23 @@ function getLoggerReplacer () {
 }
 
 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}`
 })