{"id":17447,"library":"koa-pino-logger","title":"Koa Pino Logger","description":"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.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/pinojs/koa-pino-logger","tags":["javascript","koa","http","logger","fast","pino"],"install":[{"cmd":"npm install koa-pino-logger","lang":"bash","label":"npm"},{"cmd":"yarn add koa-pino-logger","lang":"bash","label":"yarn"},{"cmd":"pnpm add koa-pino-logger","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency as it's a Koa middleware. koa-pino-logger v5 is compatible with Koa v2+.","package":"koa","optional":false},{"reason":"Core logging library used by the middleware. Users are expected to have pino installed, especially for CLI tools like `pino-pretty`.","package":"pino","optional":false}],"imports":[{"note":"While the example uses `require()`, modern Koa applications often use ESM. The default export is the middleware function.","wrong":"const koaPinoLogger = require('koa-pino-logger').default","symbol":"koaPinoLogger","correct":"import koaPinoLogger from 'koa-pino-logger'"},{"note":"CommonJS `require('koa')` is still prevalent in older projects, but `import Koa from 'koa'` is standard for ESM.","wrong":"const Koa = require('koa')","symbol":"Koa","correct":"import Koa from 'koa'"},{"note":"Types for Koa's middleware are generally imported from 'koa' or '@types/koa'. koa-pino-logger extends `ctx.log`.","wrong":"import { KoaMiddleware } from 'koa'","symbol":"Middleware","correct":"import { Middleware } from 'koa'"}],"quickstart":{"code":"import Koa from 'koa';\nimport pinoLogger from 'koa-pino-logger';\n\nconst app = new Koa();\n\n// Initialize the logger middleware\nconst loggerMiddleware = pinoLogger();\napp.use(loggerMiddleware);\n\n// Access the logger via ctx.log within downstream middleware\napp.use((ctx) => {\n  ctx.log.info({ user: 'example-user' }, 'Request processed for user');\n  ctx.body = 'Hello world with logging';\n});\n\nconst PORT = process.env.PORT ?? 3000;\napp.listen(PORT, () => {\n  console.log(`Server listening on port ${PORT}`);\n  console.log('Test with: curl http://localhost:3000 | pino');\n});","lang":"javascript","description":"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."},"warnings":[{"fix":"Upgrade your Node.js runtime to version 18 or higher.","message":"Version 5.0.0 drops support for Node.js 12 and adds support for Node.js 18. Ensure your environment meets this new requirement.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Review Pino v7 release notes and adapt any custom Pino configurations, especially around transports and exit handling.","message":"Version 4.0.0 updated to use `pino@7`. This may introduce breaking changes or deprecations inherited from Pino itself, particularly concerning how transports work with `pino.transport` and handling of `pino.final()`.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"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.","message":"koa-pino-logger is designed for Koa v2 and above. Using it with Koa v1 (which uses generator functions) will lead to compatibility issues.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Add `app.silent = true;` after `const app = new Koa();` to suppress Koa's default error logging.","message":"When logging thrown errors, Koa's default error handling prints to `console.error`. To prevent duplicate output with `koa-pino-logger`, set `app.silent = true` on your Koa application instance.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'5.0.0':27 'align':74 'altern':39 'applic':23 'arbitrari':60 'avoid':63 'bunyan':43 'cadenc':70 'critic':102 'current':24 'data':61 'differenti':36 'effici':97 'environ':93 'eval':65 'fast':110 'favor':90 'framework':86 'high':11 'high-perform':10 'http':108 'integr':16 'javascript':106 'json':19,56 'koa':1,5,13,42,46,50,85,107 'koa-bunyan-logg':41 'koa-logg':45 'koa-morgan':49 'koa-pino-logg':4 'like':40 'log':32,95 'logger':3,7,20,44,47,82,109 'major':76 'middlewar':14 'minim':34 'morgan':51 'nativ':55 'observ':104 'offer':29 'output':57,100 'overhead':35 'particular':89 'perform':12,67 'pino':2,6,18,81,111 'platform':105 'process':96 'product':92 'rapid':30 'releas':69 'speed':54 'sporad':72 'structur':31,99 'support':58 'typic':73 'under':80 'updat':77 'version':26 'web':22","created_at":"2026-04-22T17:41:47.119322+00:00","updated_at":"2026-04-22T17:41:47.119322+00:00","problems":[{"fix":"Ensure `app.use(logger());` is called early in your Koa application's middleware chain, before any middleware that attempts to use `ctx.log`.","cause":"The `koa-pino-logger` middleware was not applied to the Koa application, or `ctx.log` is being accessed before the middleware has executed for a given request.","error":"TypeError: ctx.log is undefined"},{"fix":"Install Koa: `npm install koa` or `yarn add koa`.","cause":"The `koa` package, a peer dependency, is not installed in the project.","error":"Error: Cannot find module 'koa'"},{"fix":"Install Pino: `npm install pino` or `yarn add pino`. Ensure it's available for `koa-pino-logger` to use.","cause":"The `pino` package, a peer dependency, is not installed, or `koa-pino-logger`'s internal dependency resolution for `pino` failed.","error":"Error: Cannot find module 'pino'"},{"fix":"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');`).","cause":"Attempting to use `app.use` on an object that is not a Koa application instance, or `Koa` was imported incorrectly.","error":"TypeError: app.use is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/pinojs/koa-pino-logger","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/koa-pino-logger","openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-21","install_tag":null}}