npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

koa-consolelogger

v1.2.1

Published

A development-first console-friendly logging middleware for Koa

Downloads

78

Readme

Koa Console Logger

Koa Console Logger! A lightweight middleware for Koa (v2+) that prints structured HTTP request/response logs to the console/stdout. It helps monitor HTTP traffic and errors with useful metadata such as response time in microseconds, response size, request ids, deployment ids, flow information and custom context or error fields.

  • Works with Koa 2+
  • Logs errors and successful requests
  • Response time in microseconds
  • Response size reporting
  • Request id and deployment id support
  • Custom parameter functions
  • Extra context via ctx.state.cklcontext
  • Extra error fields via Error.log (configurable key)

Install

npm

npm install koa-consolelogger

Quick start

Default logger:

import Koa from 'koa';
import logger from 'koa-consolelogger';

const app = new Koa();
app.use(logger); // default middleware

Custom configuration:

import Koa from 'koa';
import { CKLogger } from 'koa-consolelogger';

const config = {
  deploymentId: 'prod-1',
  errorDataKey: 'data' // reads Error.data for extra error fields instead of Error.log
};

const logger = CKLogger(config);
const app = new Koa();
app.use(logger);

Configuration options

The library reads its runtime options from the ICKLConfig interface. Below are the option names and what they do (use when calling CKLogger(config) or when creating a custom logger).

  • deployId?: string
    Optional deployment identifier included on every log. If not set a random id is generated per logger instance.

  • stringify?: boolean
    Optional. Not enabled yet! When extra context or error fields are objects, should they be JSON.stringified before being included in logs.

  • chalk?: boolean
    Optional. Not enabled yet! Controls colored output. Set to false to disable colors.

  • break?: string
    Optional. Separator character used between log parts. Default: '~'.

  • order?: Array
    Optional. Controls the order of fields printed for each request. Keys must match properties from ICKLParameters. If you create your own parameters function you'll have to extend this type

  • errorDataKey?: string
    Optional. Name of the property on Error instances that holds extra error fields (default: log). The logger will read Error[config.errorDataKey] if present.

  • extraParamsFn?: TCKLParamsFn
    Optional. A function to compute or augment extra parameters for each log entry These parameters will be added on top of any pre-generated parameters, so that means they're completely overridable! Example:

    const extraParamsFn = (ctx, config, err, params) => {
      return { tenant: ctx.state?.tenant || 'unknown' };
    };
    app.use(CKLogger({ extraParamsFn }));

Notes:

  • All options are optional; unspecified fields fall back to the library's internal defaults (eg: deployId is generated when not supplied).
  • For extra request context use ctx.state.cklogger, or use your own custom extraParamsFn
  • Koa automatically adds the 3rd parameter of ctx.throw() to the Error object if you provide it as an object! Just set your extra data in { log: ... }

Context & Error fields

  • Add extra context for a request via ctx.state.cklcontext:
app.use(async (ctx, next) => {
  ctx.state.cklcontext = { tenant: 'acme', userId: 42 };
  ctx.body = 'Hello world!';
});
  • Add extra fields to errors using ctx.throw(): Koa's throw will include data in an error if it's the 3rd parameter, and an object. By default the logger will look for Error.log but this can be configured via errorDataKey
ctx.throw(401, 'Unauthorized', { log: { ... }});

Contributing

Contributions welcome. Please open issues or PRs.

License

MIT