1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

prettify SQL queries during debug (#3635)

* prettify SQL queries during debug

* Use sql-formatter

Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
Rigel Kent 2021-01-25 15:37:41 +01:00 committed by GitHub
parent ab398a05e9
commit 2a6cf69cff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 5 deletions

View 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,20 @@ function getLoggerReplacer () {
}
const consoleLoggerFormat = winston.format.printf(info => {
const obj = omit(info, 'label', 'timestamp', 'level', 'message')
const obj = omit(info, 'label', 'timestamp', 'level', 'message', 'sql')
let additionalInfos = JSON.stringify(obj, getLoggerReplacer(), 2)
if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = ''
else additionalInfos = ' ' + additionalInfos
if (info.sql) {
additionalInfos += '\n' + sqlFormat(info.sql, {
language: 'sql',
ident: ' '
})
}
return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}`
})