Add sql trace in error log on sequelize error

pull/965/merge
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
}
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()
})

View File

@ -22,7 +22,13 @@ function loggerReplacer (key: string, value: any) {
}
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 = ''
else additionalInfos = ' ' + additionalInfos

View File

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