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

Logger: Label loggers #40

Merged
merged 8 commits into from
Jul 2, 2021
Merged

Conversation

SimonRichardson
Copy link
Member

@SimonRichardson SimonRichardson commented Jun 25, 2021

The following allows loggers to be tagged with labels, these labels can
be used when applying the configuration. With this change users of the
logging library can change the level of a series of loggers using the
tagged label.

The driver behind this is to better expose loggers within Juju. If a
user wanted to see all HTTP client connections, then a logger will
be tagged with GetLogger('a.b.c', HTTP). Using the model-config
within Juju, it will be possible to set [HTTP]=TRACE and all HTTP
loggers will be set to the appropriate level.


Concerns:

  1. No validation on namespaces for loggers is performed, other than
    ensuring that ";" and "." are split. Meaning that "[]" for label syntax
    might already exist in the wild?
  2. What do we do about malformed "[", or "]" labels?

Alternative syntax for labels:

  1. "<>"
  2. "{}"

See: #39

The following allows loggers to be tagged with labels, these labels can
be used when applying the configuration. With this change users of the
logging library can change the level of a series of loggers using the
tagged label.

The driver behind this is to better expose loggers with in Juju. If a
user wanted to see all http client connections, then a logger will
be tagged with `GetLogger('???', HTTP)`. Using the model-config
within Juju, it will be possible to set `[HTTP]=TRACE` and all HTTP
loggers will be set to the appropriate level.

---

Concerns:

 1. No validation on namespaces for loggers are performed, other than
 ensuring that ";" and "." are split. Meaning that "[]" for label syntax
 might already exist in the wild?
 2. What do we do about malformed "[", or "]" labels?

---

Alternative syntax for labels:

 1. "<>"
 2. "{}"
@jameinel
Copy link
Member

I feel like if we annotate loggers with labels, those labels should end up part of the log messages that they generate, so that it can be filtered early or late with the normal filtering mechanisms. (Like we do with juju debug-log --include-module unit.foo/0, something like juju debug-log --include-labels a,b,c

To allow debug-log to see a label, we need to add Labels to loggo.Entry.
When logging using Logf we just get the module and grab the labels if
there are any.
@SimonRichardson
Copy link
Member Author

@jameinel I've added labels to LogEntry, which will then allow debug-log to include/exclude based on the label.

context.go Outdated Show resolved Hide resolved
Parsing the label from the namespace was susceptible of a slight edge
case, where the validation and the extraction might differ. This fixes
that problem by using the same method for each.
Copy link

@achilleasa achilleasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; left one small note

config.go Outdated Show resolved Hide resolved
@SimonRichardson
Copy link
Member Author

!!build!!

context_test.go Outdated Show resolved Hide resolved
The following changes move a label from `[LABEL]` to `#label`, which
removes the syntax ambiguity. The old format looks like a slice/array so
users might be inclined to do `[LABEL,OTHER]` and that becomes very
confusing.
@SimonRichardson
Copy link
Member Author

@jameinel Changed to #label (prefix + name) for label syntax. Labels are lowercased in the same way that levels are, I'm wondering if namespaces should also be lowercased, or maybe that ship has sailed?

To aid with discoverability we should be able to log all the labels for
a given context.
When calling Child on a given logger, the method should pass through the
labels so that any new logger is also created with the appropriate
labels.

Exposing Labels on a logger now allows us to ensure that the labels are
indeed set correctly.
To prevent churn on the version of loggo, add a method so we keep
backwards compatible.
@SimonRichardson
Copy link
Member Author

$$merge$$

@jujubot jujubot merged commit 48aac3f into juju:master Jul 2, 2021
@SimonRichardson SimonRichardson deleted the labelled-logger branch March 16, 2023 19:59
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

Successfully merging this pull request may close these issues.

4 participants