google / flogger

A Fluent Logging API for Java
Apache License 2.0
1.45k stars 123 forks source link

Added a rate limited warning log when using context methods which can fail. #335

Closed copybara-service[bot] closed 1 year ago

copybara-service[bot] commented 1 year ago

Added a rate limited warning log when using context methods which can fail.

The static methods in ScopedLoggingContexts for adding metadata to an existing context have shown themselves to be very error prone in Google since people often assume that they will always succeed. While there are some valid uses for these methods, most usage fails to take into account the chance of failure.

The robust way to add metadata to a context is to do it when constructing a new context, such as:

ScopedLoggingContexts.newContext().withTags(...).run(...);

RELNOTES=Added warning log when using context methods which can fail.