feat: Add optional http logging in production (#2183)

* feat: Add optional http logging in production
closes #2174

* Update app.js
This commit is contained in:
Tom Moor 2021-06-05 15:19:54 -07:00 committed by GitHub
parent f517a2cecb
commit 5c7f2cf164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 17 deletions

View File

@ -101,7 +101,7 @@ MAXIMUM_IMPORT_SIZE=5120000
# You may enable or disable debugging categories to increase the noisiness of
# logs. The default is a good balance
DEBUG=cache,presenters,events,emails,mailer,utils,multiplayer,server,services
DEBUG=cache,presenters,events,emails,mailer,utils,http,server,services
# Comma separated list of domains to be allowed to signin to the wiki. If not
# set, all domains are allowed by default when using Google OAuth to signin

View File

@ -124,7 +124,7 @@
"koa-convert": "1.2.0",
"koa-helmet": "5.2.0",
"koa-jwt": "^3.6.0",
"koa-logger": "^2.0.1",
"koa-logger": "^3.2.1",
"koa-mount": "^3.0.0",
"koa-onerror": "^4.0.0",
"koa-router": "7.0.1",
@ -231,4 +231,4 @@
"js-yaml": "^3.13.1"
},
"version": "0.56.0"
}
}

View File

@ -1,5 +1,6 @@
// @flow
import * as Sentry from "@sentry/node";
import debug from "debug";
import Koa from "koa";
import compress from "koa-compress";
import helmet, {
@ -21,6 +22,7 @@ import updates from "./utils/updates";
const app = new Koa();
const isProduction = process.env.NODE_ENV === "production";
const isTest = process.env.NODE_ENV === "test";
const log = debug("http");
// Construct scripts CSP based on services in use by this installation
const defaultSrc = ["'self'"];
@ -105,11 +107,16 @@ if (isProduction) {
})
)
);
app.use(logger());
app.use(mount("/emails", emails));
}
// redirect routing logger to optional "http" debug
app.use(
logger((str, args) => {
log(str);
})
);
// catch errors in one place, automatically set status and response headers
onerror(app);

View File

@ -3401,12 +3401,7 @@ busboy@^0.2.11:
dicer "0.2.5"
readable-stream "1.1.x"
bytes@1:
version "1.0.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-1.0.0.tgz#3569ede8ba34315fab99c3e92cb04c7220de1fa8"
integrity sha1-NWnt6Lo0MV+rmcPpLLBMciDeH6g=
bytes@3.1.0:
bytes@3.1.0, bytes@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==
@ -8062,13 +8057,13 @@ koa-jwt@^3.6.0:
koa-unless "1.0.7"
p-any "1.1.0"
koa-logger@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/koa-logger/-/koa-logger-2.0.1.tgz#3ee42f457c40fb4d4a19a131c8022504b5b232b8"
integrity sha1-PuQvRXxA+01KGaExyAIlBLWyMrg=
koa-logger@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/koa-logger/-/koa-logger-3.2.1.tgz#ab9db879526db3837cc9ce4fd983c025b1689f22"
integrity sha512-MjlznhLLKy9+kG8nAXKJLM0/ClsQp/Or2vI3a5rbSQmgl8IJBQO0KI5FA70BvW+hqjtxjp49SpH2E7okS6NmHg==
dependencies:
bytes "1"
chalk "^1.1.3"
bytes "^3.1.0"
chalk "^2.4.2"
humanize-number "0.0.2"
passthrough-counter "^1.0.0"