Logging
April 17, 2019 ยท View on GitHub
Logging is configured under the log
configuration property.
log:
provider: http
opts:
url: http://logging-provider.org/
level: warn
Verbosity
level is the logging verbosity, controlling which events will be logged
according to their level, i.e. importance.
It can be silent, info, log, warn or error. The default value is
log.
Providers
provider specifies how to send logs.
The following providers are available: http,
debug, console and
custom.
opts are the options passed to the log provider. It is specific to each
provider.
If you want to use several log providers or use several configurations, the
log configuration property can
be an array of objects instead of a single object.
log:
- provider: http
opts:
url: http://logging-provider.org/
- provider: debug
HTTP log provider
The http log provider sends logs via HTTP.
Provider options:
url{string}- URL to send the logs tomethod{string}(default:POST) - HTTP method
log:
provider: http
opts:
url: http://logging-provider.org/
method: PUT
Console log provider
The console log provider prints logs on the console.
The output is prettified but does not contain performance monitoring nor detailed log information, so this is only meant as a development helper.
It uses the following format:
[EVENT ] [LEVEL] [HOST ID ] [PROCESS NAME] [PID ] [TIMESTAMP ] [PHASE ] [TIME ] MESSAGE
For example:
[START ] [LOG ] [24cdf75e] [Example API ] [26936] [2017-12-14 12:01:58.846] [STARTUP ] [147ms ] Server is ready
This log provider is always enabled, but can be silenced by using level
silent.
log:
provider: console
Debug log provider
The debug log provider prints logs and performance information
on the console. Since the output is not formatted, this is only meant for
debugging purpose.
log:
provider: debug
Custom log provider
When using the custom log provider, logs will be passed as
parameters to a custom report function:
- it receives the usual parameters
including
log,measuresandmeasuresmessage - it can be async or return a promise
- it can be used to simply handle events instead of logging them
Provider options:
report{function}- function fired with the log information
log:
provider: custom
report:
$ref: report_log.js
Events
Logs are triggered on the following events:
start: the server is readystop: the server has exitedfailure: a server-side error occurredcall: a request has completed, i.e. a response was sent back to the client (whether successful or not)message: generic messageperf: performance monitoring
Those events can be triggered during the following phases of the server:
startupshutdownrequest: each client requestprocess: anywhere else, e.g. unhandled exceptions or rejected promises
Log information
The payload of logs is a set of all the currently available parameters, which gives insight about everything in the current context.
Values that might be too big, such as payload, responsedata, data and
queryvars, are trimmed: only their id and operationName are kept.
Functions parameters
Besides the usual parameters, the following additional parameters are available during logging:
log{object}: object containing all the other parameters. Values that might be too big are trimmed. It can be safely serialized.event{string}: which event was triggered amongstart,stop,failure,call,messageandperfphase{string}: when was the event triggered amongstartup,shutdown,requestandprocesslevel{string}: event importance amonginfo,log,warnanderrormessage{string}: generic message summarizing the event or providing extra informationprotocols{object}- list of protocols being served. Only forstartevents. Also available as the resolved value of the promise returned byapiServer.run().http{object}: HTTP server informationhostname{string}port{string}
exit{object}- list of servers and databases successfully exited or not. For example,{ http: true, mongodb: true, ... }. Only forstopevents.error{object}: exception object. Only for eventsfailureorrequestwhen a client-side or server-side error occurs.measures{object[]}- list of performance measurements. Only forperfevents:category{string}label{string}: nameduration{number}- sum of all measures durations, in millisecondsmeasures{number[]}- each measure duration, in millisecondscount{number}- number of measuresaverage{number}- average measure duration, in milliseconds
measuresmessage{string}: console-friendly table with the same information asmeasuresduration{number}- time it took for the server to startup, shutdown or handle the client request (depending on the event), in milliseconds. Also available in response'smetadata.durationproperty. Only forperf,start,stopandcallevents.
Performance monitoring
Logs for the perf event are triggered with information about how long it took
for the server to startup, shutdown or handle a client request.
The measures, measuresmessage and duration
parameters provide the performance information.