This commit is contained in:
Simon Martín 2019-02-27 11:59:04 +01:00
parent c53ed67252
commit 25e54dc267
2 changed files with 6 additions and 6 deletions

View File

@ -9,7 +9,7 @@ module.exports = function log() {
request: { request: {
sql: prepareSQL(res.locals.sql) sql: prepareSQL(res.locals.sql)
} }
} };
res.set('X-SQLAPI-Log', stringifyForLogs(logObj, MAX_SQL_LENGTH)); res.set('X-SQLAPI-Log', stringifyForLogs(logObj, MAX_SQL_LENGTH));
@ -25,16 +25,16 @@ function prepareSQL(sql) {
if (typeof sql === 'string') { if (typeof sql === 'string') {
return { return {
simple: sql.substring(0, MAX_SQL_LENGTH) simple: sql.substring(0, MAX_SQL_LENGTH)
} };
} }
if (Array.isArray(sql)) { if (Array.isArray(sql)) {
return { return {
multiple: sql.map(q => q.substring(0, MAX_SQL_LENGTH)) multiple: sql.map(q => q.substring(0, MAX_SQL_LENGTH))
} };
} }
return { return {
other: sql other: sql
} };
} }

View File

@ -11,7 +11,7 @@ module.exports = {
stringifyForLogs(object, max_string_length = 1024) { stringifyForLogs(object, max_string_length = 1024) {
return JSON.stringify(cloneAndFilter(object, max_string_length)); return JSON.stringify(cloneAndFilter(object, max_string_length));
} }
} };
function cloneAndFilter(object, max_string_length) { function cloneAndFilter(object, max_string_length) {
if (!object || !(object instanceof Object)) { if (!object || !(object instanceof Object)) {
@ -22,7 +22,7 @@ function cloneAndFilter(object, max_string_length) {
Object.keys(object).map(key => { Object.keys(object).map(key => {
if (typeof object[key] === 'string') { if (typeof object[key] === 'string') {
newObject[key] = filterString(object[key], max_string_length) newObject[key] = filterString(object[key], max_string_length);
} else if (typeof object[key] === 'object') { } else if (typeof object[key] === 'object') {
newObject[key] = cloneAndFilter(object[key], max_string_length); newObject[key] = cloneAndFilter(object[key], max_string_length);
} else if (object[key] instanceof Array) { } else if (object[key] instanceof Array) {