koa-pino-logger is a high-performance Koa middleware for integrating the Pino JSON logger into web applications. Currently at version 5.0.0, it offers rapid, structured logging with minimal overhead, differentiating itself from alternatives like koa-bunyan-logger, koa-logger, and koa-morgan through its speed, native JSON output, support for arbitrary data, and avoidance of `eval` for performance. Its release cadence is sporadic, typically aligning with major updates to the underlying `pino` logger or the `Koa` framework. It's particularly favored for production environments where log processing efficiency and structured output are critical for observability platforms.
npm install koa-pino-loggerVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up `koa-pino-logger` in a basic Koa application to automatically log requests and allows accessing the logger instance on `ctx.log` for custom logging within middleware.
Upgrade your Node.js runtime to version 18 or higher.
Review Pino v7 release notes and adapt any custom Pino configurations, especially around transports and exit handling.
Ensure your Koa application is running on Koa v2 or later. If on Koa v1, refer to the `v1 readme` on the package's GitHub or migrate your Koa application.
Add `app.silent = true;` after `const app = new Koa();` to suppress Koa's default error logging.
Ensure `app.use(logger());` is called early in your Koa application's middleware chain, before any middleware that attempts to use `ctx.log`.
Install Koa: `npm install koa` or `yarn add koa`.
Install Pino: `npm install pino` or `yarn add pino`. Ensure it's available for `koa-pino-logger` to use.
Verify that `app` is an instance of `Koa` (e.g., `const app = new Koa();`) and that `koa` is correctly imported (e.g., `import Koa from 'koa';` or `const Koa = require('koa');`).