Morgan based logger for usage in a microservices architecture.


stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
00Aug 7, 2018Jul 8, 2018Minified + gzip package size for @usvc/logger-request in KB



Morgan based logger for usage in a microservices architecture.

The output logs will include the following properties:

Key Description
level This will always be "access"
method The method of the HTTP request
url The requested URL
status The status code of the request
contentLength The content length
responseTimeMs The response time in milliseconds
httpVersion The HTTP version
referrer The referrer (if applicable)
remoteHostname The remote hostname (if found)
remoteAddress The remote IP address
serverHostname The server hostname as specified in the createLogger method
time ISO timestamp of the request
userAgent User agent of the request


  • Creates an Express compatible request logger middleware
  • Allow for token extension
  • Allow for specification of a custom logger and log level


npm i @usvc/logger-request;
# OR
yarn add @usvc/logger-request;


// es5:
const {createLogger} = require('@usvc/logger-request');
// es6:
import {createLogger} from '@usvc/logger-request';


const express = require('express');
// require as ^
const app = express();

Full Configuration

const express = require('express');
// require as ^
const app = express();


API Documentaiton


Creates the request logger middleware and returns an Express compatible middleware that you can app.use(...).


Key Defaults To Description
additionalTokens [] Additional tokenizers. Each item in the array should be of the form {id: 'some-property', fn: (req, res) => (/*your code here*/)}.
hostname `os.hostname()
logger console The logger to be used.
level info The level of the logger to be used.


This function returns an array of tokenizers that you can use in the additionalTokenizers option in createLogger().

These tokenizers depend on there being a .context property in the Request object passed by Express. This is automatically done if you are using the Zipkin tracer as defined in @usvc/tracer.

Using the returned tokenizers will result in the following additional keys in the log:

Key Description
traceId The trace ID
spanId The span ID
parentSpanId The parent span ID
sampled Indication whether the request was sampled or not


Usage with ES5

Goto: ./example/es5

Or run: npm run eg:es5

Usage with ES6

Goto: ./example/es6

Or run: npm run eg:es6

Usage with Winston

Goto: ./example/winston

Or run: npm run eg:winston


See the development instructions on the main repository's README.


This package is licensed under the MIT license.

View the license at LICENSE.




Name Email Website About Me
Joseph dev-at-joeir-dot-net https://github.com/zephinzer N/A


If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.