# Logging — Fastify

Source: https://www.geekswithgeeks.com/hi/fastify/ff-logging

> Structured logging के लिए Pino (Fastify का built-in logger) उपयोग करें।

## Pino: तेज़ structured logging

Fastify के साथ Pino आता है, एक high-performance JSON logger। Routes और plugins में इसे `fastify.log` के माध्यम से access करें।

## Context के साथ logging

Better debugging और monitoring के लिए structured data के साथ log करें।

```javascript
fastify.get('/users/:id', async (req, reply) => {
  fastify.log.info({
    userId: req.params.id,
    method: req.method,
    timestamp: new Date().toISOString(),
  }, 'Fetching user');
  
  try {
    const user = await findUser(req.params.id);
    return user;
  } catch (err) {
    fastify.log.error({
      userId: req.params.id,
      error: err.message,
    }, 'Failed to fetch user');
    throw err;
  }
});
```
