Verified Commit 93ffef23 authored by Chocobozzz's avatar Chocobozzz
Browse files

Use sql-formatter

parent d1cfb0df
// 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 { prettify } = require('sql-log-prettifier')
const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
......@@ -48,22 +48,10 @@ const consoleLoggerFormat = winston.format.printf(info => {
else additionalInfos = ' ' + additionalInfos
if (info.sql) {
additionalInfos += '\n' + prettify(info.sql, {
settings: {
operators: {
color: '#808080'
},
functions: {
color: '#808080'
},
keywords: {
color: '#808080'
},
strings: {
color: '#808080'
}
}
}).replace(/^(?!\s*$)/gm, ' ') // indent by 2 spaces relative to the log beginning
additionalInfos += '\n' + sqlFormat(info.sql, {
language: 'sql',
ident: ' '
})
}
return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}`
......
......@@ -69,7 +69,7 @@ const sequelizeTypescript = new SequelizeTypescript({
logging: (message: string, benchmark: number) => {
if (process.env.NODE_DB_LOG === 'false') return
let newMessage = 'executed'
let newMessage = 'Executed SQL request'
if (isTestInstance() === true && benchmark !== undefined) {
newMessage += ' in ' + benchmark + 'ms'
}
......
......@@ -7259,20 +7259,12 @@ sprintf-js@~1.0.2:
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=
sql-formatter@^2.3.3:
version "2.3.4"
resolved "https://registry.yarnpkg.com/sql-formatter/-/sql-formatter-2.3.4.tgz#85ff9a946d8157e3917c0b1db514ca8184a1b6f1"
integrity sha512-CajWtvzYoBJbD5PQeVe3E7AOHAIYvRQEPOKgF9kfKNeY8jtjBiiA6pDzkMuAID8jJMluoPvyKveLigSaA5tKQQ==
sql-formatter@^4.0.0-beta.0:
version "4.0.0-beta.0"
resolved "https://registry.yarnpkg.com/sql-formatter/-/sql-formatter-4.0.0-beta.0.tgz#4981ecf86268184a61f19745d820a70c947a7d3f"
integrity sha512-ltWCnnig6UNvnl6MFAoegO13xiET2trcX8Idbq1LBpkCCOn9x/V2Gqs6Md+fGxnpkP8dMtUM1HWHdUYGuEDfSg==
dependencies:
lodash "^4.17.20"
sql-log-prettifier@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/sql-log-prettifier/-/sql-log-prettifier-0.1.2.tgz#d9ed1f1c8ab0dd5383c3bb97215f41025c088c25"
integrity sha512-UrTd9OlG9vBCwterrLNHHVrVnzaTCwBo2gtFHalofJXpDHnrDMBjuEM/Walxadq7+jaBmIsy6OTTmJpphbMmmg==
dependencies:
chalk "^4.1.0"
sql-formatter "^2.3.3"
argparse "^2.0.1"
srt-to-vtt@^1.1.2:
version "1.1.3"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment