Skip to content

Support for implicit contextual parameters #5

Description

@rraziel

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

The logger requires explicit parameters.

Expected behavior

Having the ability for logs to be augmented with implicit contextual information, e.g.:

interface ContextualInformationResolver {
  resolveContextualInformation(): Promise<Record<string, unknown>>;
}

@Injectable({
  providedIn: 'root'
})
class MyContextualInformationResolver implements ContextualInformationResolver {
  async resolveContextualInformation(): Promise<Record<string, unknown>> {
    return {
      // context
    };
  }
}

The contextual information would not used in the log message itself but rather as a separate context (that could still be used when formatting the log though, just like a timestamp).

Minimal reproduction of the problem with instructions

n/a

What is the motivation / use case for changing the behavior?

There is often information that would be useful to see with a log message but is not readily available where the message is logged (not to mention it could lose some of its structure if passed in the message itself).

Typical use cases would be:

  • a correlation identifier
  • a span/parent identifier
  • (not relevant if the library is only used on the front-end) a user identifier, a tenant identifier, etc.

This can make it much easier to filter logs based on such information without having to pass it manually each time a log is created in the user code.

Some examples:

Moreover, most protocols/tools related to logging support passing such contextual information (e.g. Logstash, Kibana, etc.).

Environment

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions