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
Replacing "level" field #25
Comments
This is a curious request. What is the use case? In my experience it is not typical to store the leveled loggers in variables, but rather to treat them as one time use loggers like this:
Mutating an existing contextual logger is a non-starter. By design, the keyvals carried by contextual loggers are immutable. So If the idea is to save memory allocations I am not sure there are big gains to be had here since both I am not excited about this idea, but could perhaps be persuaded by a good use case or some benchmarks showing a worthwhile improvement over the existing code. I am willing to review a PR if you want to explore this idea, but will not promise it will be accepted. Fair warning that the bar will be high. |
The solution here may be to clarify this expectation in the docs. |
The goal here is not to mutate an existing logger, but just to avoid "level" key to be present several times in the resulting logger when we call Take a library accepting a In such case and knowing this context, using That is why it could be useful to have such a Note that it is a bit counterintuitive that a logger issued from |
Yes, we should make this intuitive. The output of e.g. In other words,
Package log is not intended to be used this way. It is expected that every log statement begin with |
OK. |
Hi,
produces the following output playground:
so
level
appears twice in last log.What do you think about adding a new function in log:
which works as
log.With
but replace keyk
if it already exists, inlogger
, in the new returnedLogger
instance?So
level.{Debug,Error,Info,Warn}
can use it instead oflog.WithPrefix
as now.Replace
could be variadic asWith*
functions, but is there a real need?If you are interested (variadic or not), I can provide a PR.
The text was updated successfully, but these errors were encountered: