Logger
A module for managing an expressify logger
- expressify/logger
- createLogger(options) ⏏
- .isCompatible(logger) ⇒
boolean
- .contextDefinitions(baseLogger) ⇒
Object
- .isCompatible(logger) ⇒
- createLogger(options) ⏏
createLogger(options) ⏏
Create a bunyan logger instance. Check https://github.com/trentm/node-bunyan for documentation on some of the options below.
Kind: Exported function
Param | Type | Default | Description |
---|---|---|---|
options | Object |
Options for creating a logger | |
options.name | string |
Name for the logger, usually the name of your app | |
[options.level] | string |
Minimum log level | |
[options.logUnhandled] | boolean |
Add listeners for unhandled errors and log these | |
[options.serializers] | Object |
Add custom serializers | |
[options.stdout] | Object | boolean |
Disable or configure stdout stream |
|
[options.stdout.level] | string |
Set a different level for stdout | |
[options.stdout.notify] | boolean |
true |
Log a message when stdout logger is created |
[options.loggly] | Object | boolean |
Disable or configure loggly stream |
|
options.loggly.token | string |
Your loggly token (required to enabled loggly) | |
options.loggly.subdomain | string |
Your loggly subdomain (required to enabled loggly) | |
options.loggly.tags | Array.<string> |
Tags to attach to logs sent by this logger | |
[options.loggly.level] | string |
Set a different level for loggly | |
[options.loggly.notify] | boolean |
true |
Log a message when moggly logger is created |
createLogger.isCompatible(logger) ⇒ boolean
Check whether a logger is compatible with expressify.
Kind: static method of createLogger
Returns: boolean
- Whether ot not it is compatible
Param | Type | Description |
---|---|---|
logger | Object |
The logger object to check for compatibility |
createLogger.contextDefinitions(baseLogger) ⇒ Object
Get some definitions to use with the context middleware. It will add a logref and logger to the context when used. Logref tries to detect Heroku’s X-Request-Id and falls back to generating a UUID. The logger is extended from baseLogger and pre-configured with logref and the current request .
Kind: static method of createLogger
Returns: Object
- Definitions to use with context middleware
Param | Type | Description |
---|---|---|
baseLogger | Object |
an expressify-compatible logger |
Example
const createContextMiddleware = require('@ambassify/expressify/middleware/context');
const contextDefinitions = require('@ambassify/expressify/logger').contextDefinitions;
const logger = require('@ambassify/expressify/logger')({ level: 'info' });
createContextMiddleware({ ...contextDefinitions(logger) })