Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

koa-smplog

finboxio140MIT0.6.1

smplogging koa requests

log, smplog, koa

readme

koa-smplog

Simple request logging for koa using finboxio/smplog

Usage

var Koa = require('koa')
var Log = require('koa-smplog')

// These are default tags you want added to each log line
var defaults = { app: 'my-app' }

var app = Koa()
app.use(Log(defaults))

Features

Logging

koa-smplog will generate a pair of log lines for each received request (one for the request, one for the response) in a similar format to koajs/logger, but extended to support finboxio/smplog metadata and logging levels:

[info]   <-- GET /200 {"trace":"1474401843764ic0stbr8","event":"request-start"}
[info]   --> GET /200 200 10ms 3B {"trace":"1474401843764ic0stbr8","event":"request-end","method":"GET","url":"/200","status_code":200,"response_time_ms":10,"response_size_bytes":3}

Responses with status codes in the 4xx range will be logged at the warn level, while uncaught errors and responses with 5xx status codes will be logged at the error level.

Each logged response will include details about the response size, status, duration, path, and method.

If an error is thrown in the request context, a full JSON description of that error (including the stack trace) will be included in the metadata of the response log line.

Tracing

koa-smplog will also automatically generate a trace-id for every incoming request. Any log messages emitted within that request context will include this trace id, and is useful for filtering out individual request streams. If the x-request-trace header is included in the request, or this.smplog_trace is previously set on the context, koa-smplog will use this trace id instead of generating a new one. This is primarily to enable tracing individual requests across service boundaries.

Tagging

koa-smplog exposes a log instance to subsequent middleware as this.log. This can be used to log request details with the trace-id attached. It can also be tagged using this.log.tag({ prop: 'val', ... }). These tags will be added to the metadata of the final response message. Tags are accumulated, so you can tag multiple times from multiple middleware functions.

changelog

0.6.1 / 2025-09-26

  • Handle null response socket

0.5.2 / 2020-11-16

  • patch smplog

v0.5.1 / 2020-11-16

  • fix syntax error

v0.5.0 / 2020-11-14

  • Update dependencies

0.4.0 / 2018-07-30

  • Trim stack traces and support custom error formatters

0.3.0 / 2018-05-07

  • Truncate long strings in default error formatter
  • Remove non-primitive error properties from log output to prevent unexpectedly massive log lines

0.2.1 / 2017-02-03

  • upgrade packages

0.2.0 / 2017-01-31

  • remove tags patch since supported in smplog by default, drop bluebird

0.1.6 / 2016-11-28

  • update smplog

0.1.5 / 2016-11-28

  • add tests for safe error flatten
  • set max depth for error flatten

0.1.4 / 2016-11-28

  • more intelligible nested logging format

0.1.3 / 2016-10-26

  • update packages

0.1.2 / 2016-10-12

  • update request-intercept

0.1.1 / 2016-10-11

  • handle undefined defaults/options

0.1.0 / 2016-10-11

  • add filter function to suppress arbitrary request logs
  • make incoming request logs optional
  • strip query parameters
  • log user-agent, referer, remote-ip
  • support mounted logs
  • standardize trace header/property names
  • add request client to trace and log nested request details

0.0.3 / 2016-09-21

  • fix color tests

0.0.2 / 2016-09-21

  • colorful smplog

0.0.1 / 2016-09-20

  • Initial commit