✅ Access to child logger in beforeRouting
#1995
Replies: 5 comments 8 replies
-
it's already available for you, @williamgcampbell
could you please explain what exactly you do want? |
Beta Was this translation helpful? Give feedback.
-
Would this work for you, @williamgcampbell ? ![]() |
Beta Was this translation helpful? Give feedback.
-
I'm thinking on making it more intuitive by accepting |
Beta Was this translation helpful? Give feedback.
-
the final naming and the interface will be |
Beta Was this translation helpful? Give feedback.
-
Dear @williamgcampbell , could you please try the recently released version Here is the usage example for you: import { createConfig } from "express-zod-api";
import { randomUUID } from "node:crypto";
const config = createConfig({
logger: { level: "debug" },
childLoggerProvider: ({ parent }) =>
parent.child({ requestId: randomUUID() }),
server: {
listen: 80,
beforeRouting: ({ app, logger, getChildLogger }) => {
logger.info("This is root logger");
app.use((req, res, next) => {
getChildLogger(req).info("This is a child logger");
next();
});
},
},
}); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It looks like the logging middleware is the first thing run in
createServer
, but the request logger is tucked away in response.locals under a private metadata symbol. I could reverse engineer this and just pull the logger out using that same metadata symbol but I think there's a good case to be made for purposefully exposing that logger for other middlewares run in beforeRouting.Beta Was this translation helpful? Give feedback.
All reactions