# Request Logging with morgan & pino — Express.js Fundamentals: Routing, Middleware and APIs

Source: https://www.geekswithgeeks.com/en/expressjs/ex-logging

> Log HTTP requests with morgan for development and structured pino-http logs for production.

## morgan and pino-http

`morgan` prints readable request lines; `pino-http` emits structured JSON that log tools can search.

```javascript
import morgan from 'morgan';
import pinoHttp from 'pino-http';

if (process.env.NODE_ENV === 'production') {
  app.use(pinoHttp());
} else {
  app.use(morgan('dev'));
}

app.get('/', (req, res) => {
  req.log?.info('home visited');
  res.send('ok');
});
```

Never log passwords, tokens or full request bodies. Include a request ID so you can follow one request across log lines.
