noderus

0.4.2 • Public • Published

noderus@0.4.0 docs /Users/Nick/work/noderus documentation build index.js -f md --github

Table of Contents

setStandardFields

lib/standardFields.js:17-24

Sets up the default set of fields to be logged with every message. Call this before using the logger.

Parameters

  • service string The name of parent service
  • version string The version of the service

Examples

const { name, version } = require('./package.json')

setStandardFields(name, version)

trace

lib/basic.js:48-48

Forwards to console.log. Combines the fields provided with the standard fields.

Parameters

  • msg string The message itself
  • fields object? The collection of additional fields to log with the message

info

lib/basic.js:57-57

Forwards to console.log. Combines the fields provided with the standard fields.

Parameters

  • msg string The message itself
  • fields object? The collection of additional fields to log with the message

warn

lib/basic.js:66-66

Forwards to console.warn. Combines the fields provided with the standard fields.

Parameters

  • msg string The message itself
  • fields object? The collection of additional fields to log with the message

error

lib/basic.js:75-75

Forwards to console.error. Combines the fields provided with the standard fields.

Parameters

  • msg string The message itself
  • fields object? The collection of additional fields to log with the message

fatal

lib/basic.js:85-88

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 itself
  • fields object? The collection of additional fields to log with the message

logRequest

lib/http.js:24-36

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 itself
  • req 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

lib/http.js:60-73

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 itself
  • res 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)

Readme

Keywords

Package Sidebar

Install

npm i noderus

Weekly Downloads

1

Version

0.4.2

License

MIT

Unpacked Size

14.5 kB

Total Files

9

Last publish

Collaborators

  • nicklanng