Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom tagging or a custom context #114

Open
JonasDoe opened this issue Mar 7, 2021 · 0 comments
Open

Allow custom tagging or a custom context #114

JonasDoe opened this issue Mar 7, 2021 · 0 comments

Comments

@JonasDoe
Copy link

JonasDoe commented Mar 7, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant