Fix http requests logging

This commit is contained in:
Alice Gaudon 2020-06-14 16:04:50 +02:00
parent 98566811c3
commit a2ef0f6a42
3 changed files with 13 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "wms-core", "name": "wms-core",
"version": "0.7.2", "version": "0.7.6",
"description": "Node web framework", "description": "Node web framework",
"repository": "git@gitlab.com:ArisuOngaku/wms-core.git", "repository": "git@gitlab.com:ArisuOngaku/wms-core.git",
"author": "Alice Gaudon <alice@gaudon.pro>", "author": "Alice Gaudon <alice@gaudon.pro>",
@ -34,6 +34,7 @@
"dependencies": { "dependencies": {
"@types/express": "^4.17.6", "@types/express": "^4.17.6",
"@types/express-session": "^1.17.0", "@types/express-session": "^1.17.0",
"@types/multer": "^1.4.3",
"@types/mysql": "^2.15.10", "@types/mysql": "^2.15.10",
"@types/nodemailer": "^6.4.0", "@types/nodemailer": "^6.4.0",
"@types/nunjucks": "^3.1.3", "@types/nunjucks": "^3.1.3",

View File

@ -16,7 +16,7 @@ export default class LogRequestsComponent extends ApplicationComponent<void> {
let logStr = `${req.method} ${req.originalUrl} - ${res.statusCode}`; let logStr = `${req.method} ${req.originalUrl} - ${res.statusCode}`;
if (err) { if (err) {
if (silent) { if (silent) {
logStr += `${err.errorCode} ${err.name}`; logStr += ` ${err.errorCode} ${err.name}`;
return Logger.silentError(err, logStr); return Logger.silentError(err, logStr);
} else { } else {
return Logger.error(err, logStr, additionalStr, err); return Logger.error(err, logStr, additionalStr, err);
@ -25,7 +25,7 @@ export default class LogRequestsComponent extends ApplicationComponent<void> {
Logger.info(logStr); Logger.info(logStr);
} }
} else { } else {
const requestObj = { const requestObj = JSON.stringify({
ip: req.ip, ip: req.ip,
host: req.hostname, host: req.hostname,
method: req.method, method: req.method,
@ -34,12 +34,13 @@ export default class LogRequestsComponent extends ApplicationComponent<void> {
query: req.query, query: req.query,
params: req.params, params: req.params,
body: req.body, body: req.body,
files: req.files,
cookies: req.cookies, cookies: req.cookies,
sessionId: req.sessionID, sessionId: req.sessionID,
result: { result: {
code: res.statusCode code: res.statusCode
} }
}; }, null, 4);
if (err) { if (err) {
return Logger.error(err, requestObj, err); return Logger.error(err, requestObj, err);
} else { } else {

View File

@ -641,6 +641,13 @@
resolved "https://registry.toot.party/@types%2fmjml/-/mjml-4.0.4.tgz#af6075d29f64d47186d76125504daf544dfb2b42" resolved "https://registry.toot.party/@types%2fmjml/-/mjml-4.0.4.tgz#af6075d29f64d47186d76125504daf544dfb2b42"
integrity sha512-4PhI6iZ1zGXZ9X9W0bbmI7mS2xdxITURueqSWJ/cTeS5+tbAtOUDG1ww/fPbfcffWwR4NeOjyNcZiczafH/yfw== integrity sha512-4PhI6iZ1zGXZ9X9W0bbmI7mS2xdxITURueqSWJ/cTeS5+tbAtOUDG1ww/fPbfcffWwR4NeOjyNcZiczafH/yfw==
"@types/multer@^1.4.3":
version "1.4.3"
resolved "https://registry.toot.party/@types%2fmulter/-/multer-1.4.3.tgz#bdff74b334c38a8ee1de9fbedb5d1d3dbc377422"
integrity sha512-tWsKbF5LYtXrJ7eOfI0aLBgEv9B7fnJe1JRXTj5+Z6EMfX0yHVsRFsNGnKyN8Bs0gtDv+JR37xAqsPnALyVTqg==
dependencies:
"@types/express" "*"
"@types/mysql@^2.15.10": "@types/mysql@^2.15.10":
version "2.15.13" version "2.15.13"
resolved "https://registry.toot.party/@types%2fmysql/-/mysql-2.15.13.tgz#153dc2e2f8dffd39f7bba556c2679f14bdbecde1" resolved "https://registry.toot.party/@types%2fmysql/-/mysql-2.15.13.tgz#153dc2e2f8dffd39f7bba556c2679f14bdbecde1"