pinojs / pino-http

🌲 high-speed HTTP logger for Node.js
MIT License
527 stars 117 forks source link

How to inject request to the HttpLogger in the express middleware example? #334

Open tal-rofe98 opened 4 months ago

tal-rofe98 commented 4 months ago

I want to follow this example: https://www.npmjs.com/package/pino-http#use-as-express-middleware

but I also want to provide the logger() call with the request object. Something like this:

const logger = require('pino-http')

const app = express()

app.use((req) => logger(req))

But it does not work (it crashes my server). Is it even possible?

jsumners commented 4 months ago

Please provide a minimal reproducible example. Doing so will help us diagnose your issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code.

You may use a GitHub repository to host the code if it is too much to fit in a code block (or two).