Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #72 from BonnierNews/feature/bump-lu-logger
Browse files Browse the repository at this point in the history
Bump `lu-logger`
  • Loading branch information
MattiasOlla authored Jul 17, 2024
2 parents 802cd8b + ef07004 commit e1443aa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 97 deletions.
6 changes: 3 additions & 3 deletions lib/log-middleware.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as uuid from "uuid";
import camelcase from "camelcase";
import config from "exp-config";
import { logger } from "lu-logger";
import camelcase from "camelcase";
import * as uuid from "uuid";

import isHealthOrMetricRequest from "./is-health-or-metric-request.js";

Expand All @@ -13,7 +13,7 @@ export function setCorrelationId(req, res, next) {
if (!correlationId) {
correlationId = uuid.v4();
if (!isHealthOrMetricRequest(req)) {
logger.debug(`Didn't receive correlationId on path ${req.originalUrl}, created: ${correlationId}`, { meta: { correlationId } });
logger.debug(`Didn't receive correlationId on path ${req.originalUrl}, created: ${correlationId}`, { correlationId });
}
}
req.correlationId = correlationId;
Expand Down
13 changes: 8 additions & 5 deletions lib/middleware.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import express from "express";
import config from "exp-config";
import luLogger, { logger } from "lu-logger";
import express from "express";
import { debugMeta, logger } from "lu-logger";

import { setCorrelationId, setDebugMeta } from "./log-middleware.js";
import isHealthOrMetricRequest from "./is-health-or-metric-request.js";
import { setCorrelationId, setDebugMeta } from "./log-middleware.js";
import requestMetrics from "./request-metrics.js";
import statusShutdown from "./status-middleware-when-shutting-down.js";

Expand All @@ -27,7 +27,10 @@ function accessLog(req, res, next) {
res.removeListener("close", afterResponse);

if (!isHealthOrMetricRequest(req)) {
const meta = { ...req.debugMeta, ...(req.route && { route: req.route.path, methods: req.route.methods }) };
const meta = {
...req.debugMeta,
...(req.route && { route: req.route.path, methods: req.route.methods, statusCode: res?.statusCode }),
};
if (!res.finished) {
logger.info(`"${req.method} ${req.originalUrl}" NO RESPONSE SENT ${new Date() - time} ms`, meta);
} else {
Expand All @@ -45,7 +48,7 @@ function accessLog(req, res, next) {
export const router = express.Router(); // eslint-disable-line new-cap
router.use(setCorrelationId);
router.use(setDebugMeta);
router.use(luLogger.debugMeta.initMiddleware((req) => req.debugMeta));
router.use(debugMeta.initMiddleware((req) => req.debugMeta));
router.use(requestMetrics);
if (config.requestLogging) {
router.use(accessLog);
Expand Down
95 changes: 8 additions & 87 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lu-server",
"version": "8.1.0",
"version": "8.2.0",
"engines": {
"node": ">=18 <=20",
"yarn": "please use npm"
Expand Down Expand Up @@ -31,7 +31,7 @@
"exp-config": "^4.2.0",
"express": "^4.19.2",
"joi": "^17.7.0",
"lu-logger": "github:BonnierNews/lu-logger#semver:^7.3.1",
"lu-logger": "github:BonnierNews/lu-logger#semver:^8.0.0",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit e1443aa

Please sign in to comment.