# fastify-access-logger

> an access logger plugin for fastify

Latest version **0.2.0** (published 2019-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install fastify-access-logger
pnpm add fastify-access-logger
yarn add fastify-access-logger
bun add fastify-access-logger
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2019-01-10 |
| First published | 2019-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6.0.0 |
| Dependencies | 4 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Denis Fäcke |
| Maintainers | serayaeryn |
| Keywords | access logger, access, logger, fastify, plugin |

## Links

- npm: https://www.npmjs.com/package/fastify-access-logger
- Repository: https://github.com/SerayaEryn/fastify-access-logger
- Homepage: https://github.com/SerayaEryn/fastify-access-logger#readme
- Issues: https://github.com/SerayaEryn/fastify-access-logger/issues
- npm.io page: https://npm.io/package/fastify-access-logger

## Dependencies (4)

- [each-async](https://npm.io/package/each-async.md) ^1.1.1
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^1.4.0
- [fast-date-format](https://npm.io/package/fast-date-format.md) ^2.0.0
- [generate-function](https://npm.io/package/generate-function.md) ^2.3.1

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.2.0 (latest) — 2019-01-10
- 0.1.0 — 2019-01-09

## README

# fastify-access-logger

[![Greenkeeper badge](https://badges.greenkeeper.io/SerayaEryn/fastify-access-logger.svg)](https://greenkeeper.io/)
[![Build Status](https://travis-ci.org/SerayaEryn/fastify-access-logger.svg?branch=master)](https://travis-ci.org/SerayaEryn/fastify-access-logger)
[![Coverage Status](https://coveralls.io/repos/github/SerayaEryn/fastify-access-logger/badge.svg?branch=master)](https://coveralls.io/github/SerayaEryn/fastify-access-logger?branch=master)
[![NPM version](https://img.shields.io/npm/v/fastify-access-logger.svg?style=flat)](https://www.npmjs.com/package/fastify-access-logger)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

An access logger plugin for [fastify](http://fastify.io/).

## Installation

```
npm i fastify-access-logger
```

## Example

```js
const fastifyAccessLogger = require('fastify-access-logger')
const fastify = require('fastify')()

const options = {
  transports: [process.stdout]
}
fastify.register(fastifyAccessLogger, options)
fastify.get('/test', (request, reply) => {
  reply.send(200)
})

fastify.listen(3000)
```

## API

### fastifyAccessLogger(fastify, options, next)

The access logger plugin logs a line for every request with information about it:

```
127.0.0.1 [02/Jan/2019:17:37:12 +0100] GET /test - 200 3 3
```
The access logger plugin accepts the following options:

#### transports

An array of [Writable](https://nodejs.org/api/stream.html#stream_class_stream_writable) streams.

#### format (optional)

Allows to specify a custom format. 
The following tokens are supported:

| Token         | Description	               |
| ------------- | -------------------------- | 
| IP            | The ip address              |
| DATE          | The formatted date         |
| METHOD        | The http request method    |
| URL           | The url without parameters |
| PARAMETERS    | The url parameters         |
| STATUS        | The status code            |
| DURATION      | The duration of the request in milliseconds |
| SIZE          | The size of the payload    |

Defaults to `IP DATE METHOD URL PARAMETERS STATUS DURATION SIZE`.

#### dateFormat (optional)

The date format used to format the date token. Defaults to `[[]DD/MMM/YYYY:HH:mm:ss Z[]]`.<br>
Supports all formating options of [fast-date-format](https://github.com/SerayaEryn/fast-date-format).

## License

[MIT](./LICENSE)

---
_Source: https://npm.io/package/fastify-access-logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
