signale icon indicating copy to clipboard operation
signale copied to clipboard

Allow custom tagging or a custom context

Open JonasDoe opened this issue 3 years ago • 0 comments

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.

JonasDoe avatar Mar 07 '21 13:03 JonasDoe