# koa-logger

> Logging middleware for koa

Latest version **4.0.0** (published 2025-06-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-logger
pnpm add koa-logger
yarn add koa-logger
bun add koa-logger
```

## Health

**Score 33/100 (F)** — status: maintenance-mode.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-06-13 |
| First published | 2013-08-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/koa-logger) |
| Module format | CommonJS |
| Node | >= 18 |
| Dependencies | 5 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 560 |
| Author | Christoffer Hallas |
| Maintainers | coderhaoxin, niftylettuce, dead_horse, tjholowaychuk, jongleberry, fengmk2, 3imed-jaberi, titanism |
| Keywords | koa, middleware, logger, log |

## Links

- npm: https://www.npmjs.com/package/koa-logger
- Repository: https://github.com/koajs/logger
- Issues: https://github.com/koajs/logger/issues
- npm.io page: https://npm.io/package/koa-logger

## Dependencies (5)

- [bytes](https://npm.io/package/bytes.md) ^3.1.0
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [on-finished](https://npm.io/package/on-finished.md) ^2.4.1
- [humanize-number](https://npm.io/package/humanize-number.md) ^0.0.2
- [passthrough-counter](https://npm.io/package/passthrough-counter.md) ^1.0.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.0 (latest) — 2025-06-13
- 2.0.1 (next) — 2017-01-12
- 3.2.1 — 2019-07-17
- 3.2.0 — 2018-03-13
- 3.1.0 — 2017-09-26
- 3.0.1 — 2017-06-30
- 3.0.0 — 2017-05-16
- 1.3.1 — 2017-01-12
- 2.0.0 — 2015-11-19
- 1.3.0 — 2015-07-17
- 1.2.2 — 2014-07-06
- 1.2.1 — 2014-05-14
- 1.2.0 — 2014-02-12
- 1.1.1 — 2014-01-15
- 1.1.0 — 2013-12-21
- … 2 more at https://npm.io/package/koa-logger/versions

## README

# koa-logger

[![npm version][npm-image]][npm-url]

 Development style logger middleware for [koa](https://github.com/koajs/koa). Compatible with [request-received](https://github.com/cabinjs/request-received).

```
<-- GET /
--> GET / 200 835ms 746b
<-- GET /
--> GET / 200 960ms 1.9kb
<-- GET /users
--> GET /users 200 357ms 922b
<-- GET /users?page=2
--> GET /users?page=2 200 466ms 4.66kb
```

## Installation

```js
$ npm install koa-logger
```

## Example

```js
const logger = require('koa-logger')
const Koa = require('koa')

const app = new Koa()
app.use(logger())
```

## Notes

  Recommended that you `.use()` this middleware near the top
  to "wrap" all subsequent middleware.

## Use Custom Transporter

```js
const logger = require('koa-logger')
const Koa = require('koa')

const app = new Koa()
app.use(logger((str, args) => {
  // redirect koa logger to other output pipe
  // default is process.stdout(by console.log function)
}))
```
or
```js
app.use(logger({
  transporter: (str, args) => {
    // ...
  }
}))
```

  Param `str` is output string with ANSI Color, and you can get pure text with other modules like `strip-ansi`  
  Param `args` is a array by `[format, method, url, status, time, length]`

## License

  MIT

[npm-image]: https://img.shields.io/npm/v/koa-logger.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/koa-logger

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