1
0
Fork 0

Add sql trace in error log on sequelize error

This commit is contained in:
Chocobozzz 2018-08-31 11:43:46 +02:00
parent d6ca951b3c
commit 328e607d32
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 14 additions and 3 deletions

View file

@ -166,7 +166,10 @@ app.use(function (err, req, res, next) {
error = err.stack || err.message || err error = err.stack || err.message || err
} }
logger.error('Error in controller.', { err: error }) // Sequelize error
const sql = err.parent ? err.parent.sql : undefined
logger.error('Error in controller.', { err: error, sql })
return res.status(err.status || 500).end() return res.status(err.status || 500).end()
}) })

View file

@ -22,7 +22,13 @@ function loggerReplacer (key: string, value: any) {
} }
const consoleLoggerFormat = winston.format.printf(info => { const consoleLoggerFormat = winston.format.printf(info => {
let additionalInfos = JSON.stringify(info.meta || info.err, loggerReplacer, 2) const obj = {
meta: info.meta,
err: info.err,
sql: info.sql
}
let additionalInfos = JSON.stringify(obj, loggerReplacer, 2)
if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = '' if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = ''
else additionalInfos = ' ' + additionalInfos else additionalInfos = ' ' + additionalInfos

View file

@ -31,6 +31,8 @@ function cacheRoute (lifetimeArg: string | number) {
logger.error('Cannot cache route.', { err }) logger.error('Cannot cache route.', { err })
return done(err) return done(err)
}) })
} else {
done()
} }
return sendSave(body) return sendSave(body)
@ -52,7 +54,7 @@ function cacheRoute (lifetimeArg: string | number) {
return done() return done()
}) })
} catch (err) { } catch (err) {
logger.error('Cannot serve cached route.', err) logger.error('Cannot serve cached route.', { err })
return next() return next()
} }
} }