serviceberry-logger

2.1.0 • Public • Published

serviceberry-logger

CircleCI Test Coverage Maintainability npm version

A logger plugin for Serviceberry.

Logs HTTP requests and responses and attaches a child logger to each request at request.log. Loggers are winston loggers.

Install

npm install serviceberry-logger

Example

logger = require("serviceberry-logger");

trunk.use(logger("server.log"))
	.catch(logger.error);

Each request is logged when received as

  • message request
  • id string
  • ip string
  • method string
  • host string
  • url string
  • headers object

Each response is logged when finished as

  • message response
  • id string
  • elapsed number milliseconds
  • status
    • code number
    • text string
  • headers object

Child loggers for each request are bound with the request id so all log output for a given request is easy to find. Logging within other request handlers can be done like this

request.log.info("some awesome message");

or

request.log.warn("Watch out!", {danger: true});

See winston for more details.

Reference

serviceberry-logger can be called with one of two signatures.

logger(path)

  • path string

    The path to the log file such as logs/server.log.

logger(options)

  • options object

    • path string

      See above

    • console boolean

      Set to false to stop the plugin from adding a stock console transport that prints logs to stdout and stderr.

    • All other properties are the meta data included with the logs

logger.error(request)

serviceberry-logger provides a convenient Serviceberry style catch handler if you'd like to log errors as well.

  • request object

    Serviceberry request object

Package Sidebar

Install

npm i serviceberry-logger

Weekly Downloads

8

Version

2.1.0

License

MIT

Unpacked Size

9.71 kB

Total Files

5

Last publish

Collaborators

  • bob-gray