Simple HTTP request logger middleware for express.js inspired by koa-logger, written in typescript.
This is a Node.js module available through the npm registry. Installation is done using the
npm install
command:
$ npm install chrona
var chrona = require('chrona')
app.use(chrona())
Make sure to add chrona to first in middleware chain.
Create a new chrona middleware function using the given format
and options
. By default, it creates with default format
and default options
value.
The format
argument is a string of predefined token names(see below for token names).
- :incoming
- :[incoming]
- :remote-address
- :[remote-address]
- :date
- :[date]
- :method
- :[method]
- :url
- :[url]
- :http-version
- :[http-version]
- :status
- :[status]
- :content-length
- :[content-length]
- :response-time
- :[response-time]
- :referrer
- :[referrer]
- :user-agent
- :[user-agent]
:incoming is special one, If format string contains it, it add directional arrows(
-->
) for incoming request and outgoing response in log string.
app.use(chrona(":incoming :method :url :status :response-time :content-length :user-agent :http-version"))
chroma accepts options argument as a function or an object. Right now chroma has only one option call transporter which can be provided
either by passing function or an object with transporter key. Transporter is for change chrona's default transporter(where to show log messages)
which is console.log
.
// If you want to go with default format string, then just pass
// empty string or null
app.use(chrona(null, function(str, args) => {
// pass str and args to your own transporter like winston etc.
}))