Skip to content

Allow custom tagging or a custom context #114

@JonasDoe

Description

@JonasDoe

Is your feature request related to a problem? Please describe.
I wan to create some kind of audit log. It would be nice if I could add more and more tags to a logger the deeper I go the inner contexts - similar to the scope property, but where new scopes get appended and do not override the given ones - for the current contexts and its subcontexts. Outer contexts shouldn't be affected by added tags.

Describe the solution you'd like
One way would be a plain addTags(...tags: string[]): Signale method and an internal LoggerTags object with a logic like

class LoggerTags {
  private readonly wrapped: LoggerTags | undefined;
  private readonly newTags: string[];
  ...
  getTags(): string[]{
    return (this.wrapped?.getTags() || []).concat(this.newTags);
  }
  addTags(...toAdd: string[]): LoggerTags {
    return new LoggerTags(this, ...toAdd);
  }
}

(Ofc. this is just a rather unsecure and imperformant sketch of the idea.)

A more flexible approach would be a custom context added to a logger. There I could hold (amongst other things) the tags. But then I'ld be forced to handle the tag-immutability for outer contexts by myself, I would have to write a custom method to add the tags to a log, and there wouldn't be real type-safety.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions