Closed ronkot closed 3 years ago
@ronkot What you have provided is correct in terms of how the global options would work although that wouldn't be the way you'd want to set metadata for a single log message. Each of the log methods has the ability to take in metadata to include with the log message. For example:
log.info('R1', { event });
The global options should be used to set values that do not change. You can set data within log.options.meta
and that will be merged with any metadata that was to be passed in via a log method.
Ah, I understand. Thanks for clarification :) I just got baffled when read the first code example in README.
I'm a bit confused of how setting invocation specific data to the global log.options works. Let's consider the following case:
log.options.meta.event = event;
(event
is specific to R1)log.options.meta.event = event;
(hereevent
is specific to R2)log.info('R1')
callHave I understood this correctly? To me it seems that we just cannot use global instance to set request specific stuff. Instead, we should create an own instance of logger for each request and pass the logger as function argument downstream.
EDIT: This case assumes that the same NodeJS instance is used to serve multiple requests. AFAIK this is how Lambda (and also e.g. Azure functions) works. If we had completely separate NodeJS instances for each call, we'd not have this problem.