# Logging

## Using Logging

You can use the logger by first initializing it within the `composeRoutes` function you can pass it `true` as a value to just use the default setup like so

```javascript
const { router } = require('octoris')

router.composeRoutes({ logger: true }, [routes])

```

{% hint style="info" %}
&#x20;The logger uses the [Pino](https://www.npmjs.com/package/pino) package to do the actual logging check it's documentation for the different functions it has available.
{% endhint %}

You can also pass the logger a options object that follows the [pino options object](https://github.com/pinojs/pino/blob/HEAD/docs/api.md#options)&#x20;

{% code title="routes.js" %}

```javascript
const { router } = require('octoris')

router.composeRoutes({
  logger: {
    level: 'info',
    file: '/path/to/file' // Will use pino.destination()
  }
})

```

{% endcode %}

{% hint style="info" %}
If you provide a `file` option octoris will automatically use the `pino.destination()` functionality to make sure your logs are written to that file
{% endhint %}

## Logging From Context

If you setup and decide to use the logger built into octoris, you then have it available to you from the context object passed to your routes and middleware.

```javascript
function routeHandler (ctx) {
  ctx.logger.info('Handling route!')

  return send(200, 'route handled')
}
```

{% hint style="info" %}
You can checkout the different logger methods available within the [pino documentation](https://github.com/pinojs/pino/blob/HEAD/docs/api.md#logger)
{% endhint %}
