Giter Site home page Giter Site logo

koa-smplog's Introduction

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.

koa-smplog's People

Contributors

bdentino avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.