0.1.1 • Published 3 months ago

@duccem/duccem-request-logger v0.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

Ducentrace

A middleware to trace the request and response on an express server

Installation

$ npm install --save @duccem/duccem-request-logger

Usage

const app = require('express')();
const requestLogger = require('@duccem/duccem-request-logger');

app.use(requestLogger());
app.listen(80, () => {
	console.log('Server listening on port 80');
});

Options

The options let you configure the template format and the execution order

interface RequestLoggerOptions {
  format: string; // format if immediate is true
  immediate: boolean; // to log immediate after the request start
	formatRequest?: string; // format of the request log
  formatResponse?: string; // format of the response log
} 

Formats

The list of formats by default

  • Request: "Requested :method :http-version :url from :ip :referrer :user-agent"
  • Response: "Responded to :url requested by :ip with status :status (:content-length) bytes in :response-time ms"
  • Combined: "Requested :method :http-version :url from :ip :referrer :user-agent Responded with status :status (:content-length) in :response-time ms"

Tokens

The tokens that you can use in the format

TokenDescription
:methodHTTP method
:http-versionHTTP version
:ipDirection of the requester
:statusResponse Status Code
:response-timeTime of the response end
:user-agentClient that made the request
:content-lengthSize in bytes of the response
:referrerRequest referrer

Author: Duccem