Merge pull request #4760 from specklesystems/iain/express-no-log-graphql

chore(server/logging): do not log requests to Express if logged by Apollo middleware
This commit is contained in:
Iain Sproat
2025-05-19 09:36:13 +01:00
committed by GitHub
@@ -50,14 +50,23 @@ export const sanitizeQueryParams = (
return query
}
const shouldBeLoggedAsDebug = (req: IncomingMessage) => {
const path = getRequestPath(req)
if (!path) return false
return [
'/metrics',
'/readiness',
'/liveness',
'/graphql' // graphql endpoint is logged by the graphql middleware
].includes(path)
}
export const LoggingExpressMiddleware = HttpLogger({
logger,
autoLogging: true,
genReqId: GenerateRequestId,
customLogLevel: (req, res, err) => {
const path = getRequestPath(req)
const shouldBeDebug = ['/metrics', '/readiness', '/liveness'].includes(path || '')
if (shouldBeDebug) return 'debug'
if (shouldBeLoggedAsDebug(req)) return 'debug'
if (res.statusCode >= 400 && res.statusCode < 500) {
return 'info'