noderus
v0.4.2
Published
> [email protected] docs /Users/Nick/work/noderus > documentation build index.js -f md --github
Downloads
6
Readme
[email protected] docs /Users/Nick/work/noderus documentation build index.js -f md --github
Table of Contents
setStandardFields
Sets up the default set of fields to be logged with every message. Call this before using the logger.
Parameters
Examples
const { name, version } = require('./package.json')
setStandardFields(name, version)
trace
Forwards to console.log
.
Combines the fields provided with the standard fields.
Parameters
msg
string The message itselffields
object? The collection of additional fields to log with the message
info
Forwards to console.log
.
Combines the fields provided with the standard fields.
Parameters
msg
string The message itselffields
object? The collection of additional fields to log with the message
warn
Forwards to console.warn
.
Combines the fields provided with the standard fields.
Parameters
msg
string The message itselffields
object? The collection of additional fields to log with the message
error
Forwards to console.error
.
Combines the fields provided with the standard fields.
Parameters
msg
string The message itselffields
object? The collection of additional fields to log with the message
fatal
Forwards to console.error
.
Combines the fields provided with the standard fields.
NOTE: Also exits the process with a code of 1.
Parameters
msg
string The message itselffields
object? The collection of additional fields to log with the message
logRequest
Takes an object representing an HTTP request and a message. Creates a set of logging fields to extract certain data from the request and combines them with the standard fields. Logs at level INFO.
Parameters
msg
string The message itselfreq
object A representation of an HTTP request, abstracted from any particular implentation.
Examples
// logging from koa
const request = {
header: ctx.request.header,
protocol: ctx.protocol,
remoteAddress: ctx.originalUrl,
url: ctx.url,
method: ctx.method,
contentLength: ctx.request.length
}
logRequest('HTTP request', request)
logResponse
Takes an object representing an HTTP response and a message. Creates a set of logging fields to extract certain data from the response and combines them with the standard fields. Logs at level INFO.
Parameters
msg
string The message itselfres
object A representation of an HTTP response, abstracted from any particular implentation.
Examples
// logging from koa
const response = {
header: ctx.request.header,
protocol: ctx.protocol,
remoteAddress: ctx.originalUrl,
url: ctx.url,
method: ctx.method,
contentLength: ctx.response.length,
status: ctx.status
}
logResponse('HTTP response', response)