# @schibsted/middy-access-log

> Middy middleware for logging processed requests in an access-log like fashion. Optimised for JSON loggers e.g. Bunyan or Pino.

Latest version **4.0.2** (published 2022-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @schibsted/middy-access-log
pnpm add @schibsted/middy-access-log
yarn add @schibsted/middy-access-log
bun add @schibsted/middy-access-log
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.2 |
| Published | 2022-08-29 |
| First published | 2020-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 26.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | filipgolonka, schibstedbot, joawan, gustavkj, pakerstrand |
| Keywords | Lambda, Middleware, Serverless, Framework, AWS, AWS Lambda, Middy, Access log, Logging, bunyan, pino, JSON logger |

## Links

- npm: https://www.npmjs.com/package/@schibsted/middy-access-log
- Repository: https://github.com/schibsted/middy-access-log
- Homepage: https://github.com/schibsted/middy-access-log#readme
- Issues: https://github.com/schibsted/middy-access-log/issues
- npm.io page: https://npm.io/package/@schibsted/middy-access-log

## Dependencies (1)

- [ramda](https://npm.io/package/ramda.md) ^0.28.0

## 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

- 4.0.2 (latest) — 2022-08-29
- 4.0.1 — 2022-05-19
- 4.0.0 — 2022-05-19
- 3.1.0 — 2022-03-18
- 3.0.0 — 2021-12-21
- 2.0.2 — 2021-08-12
- 2.0.0 — 2021-07-27
- 0.3.0 — 2021-02-18
- 0.2.0 — 2020-12-11
- 0.1.1 — 2020-10-29
- 0.1.0 — 2020-10-28
- 0.0.4 — 2020-10-26
- 0.0.3 — 2020-10-26

## README

# Middy access log middleware

![github checks](https://badgen.net/github/checks/schibsted/middy-access-log)
![current version @ npm](https://badgen.net/npm/v/@schibsted/middy-access-log)
![weekly downloads @ npm](https://badgen.net/npm/dw/@schibsted/middy-access-log)
![minified size](https://badgen.net//bundlephobia/min/@schibsted/middy-access-log)

#### Access log middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda

This middleware logs processed requests in an access log like fashion.
I suggest using it together with [@schibsted/middy-error-handler](https://github.com/schibsted/middy-error-handler)

This access log is optimised for JSON loggers e.g. [bunyan](https://github.com/trentm/node-bunyan) or [pino](https://getpino.io/)

Sets headers in `after` and `onError` phases.

## Install

To install this middleware you can use NPM:

```bash
npm install --save @schibsted/middy-access-log
```

## Options

- `logger` (defaults to `console`) - a logging function that is invoked with the current error as an argument. You can pass `false` if you don't want the logging to happen.
- `level` (defaults to `info`) - log level to use for the log entries
- `excludeHeaders` (array of header names, defaults to `[]`) - prevent specified headers from showing up in logs (e.g. user credentials)

See the sample usage below.

## Sample usage

```javascript
const middy = require('@middy/core');
const accessLog = require('@schibsted/middy-access-log');
const bunyan = require('bunyan');
const logger = bunyan.createLogger({name: "myapp"});

const handler = middy(async () => ({
        statusCode: 200,
        body: JSON.stringify({ foo: 'bar' }),
    }));

handler
  .use(accessLog({ logger }));
```

## Contributing

Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/schibsted/middy-access-log/issues) or to [submit Pull Requests](https://github.com/schibsted/middy-access-log/pulls).

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