-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
RFC: Logging Context with Loggable #9988
Comments
++ on having better context when logging. Another alternative is to use log4j2's thread context. I had a go at using this about a year ago, it can result in something like this: pipelines.yml: - pipeline.id: test
pipeline.workers: 1
pipeline.batch.size: 2
config.string: "input { generator {} } filter { sleep { time => 1 } } output { stdout { codec => dots } }"
- pipeline.id: broken_test
pipeline.workers: 1
pipeline.batch.size: 1
config.string: "input { stdin {} } filter { ruby { code => 'broken' } } output { stdout { codec => dots } }"
I rebased the code for this and created an experimental wip PR: #9991 Maybe we could combine your logger context strategy + log4j2's thread context to have a good balance of implicit logging metadata + providing logstash's objects with the context for them to use (either in logging or for other purposes) |
closed by merging of PR #11074 |
Mapping the logs output by logstash plugins to their causes has become
increasingly complex, especially with the advent of multiple pipelines; a
plugin may be instantiated any number of times across one or more pipelines,
and finding which instance is the origin of a particular log message is no
longer trivial.
I would like to introduce the ability for an instance that includes our
Loggable
to provide lazy default context to the underlying logger, includinghelpful key/value pairs with data like the plugin's id and/or the pipeline's
id; it could also be useful to automatically include
:exception
if thelogger is invoked while handling an exception.
Given the current state of Javafication, I'm a little unsure where this should
land, and would like conceptual validation before attempting implementation.
In my current vision, any ruby object from a class that includes our
Loggable
mixin (which currently defines an instance method#logger
) willbe able to optionally respond to
#logger_context()
. This method would berequired to return a Hash that is allowed to be frozen.
The performance cost of doing this would be one additional long-lived proxy
object per instance that includes
Loggable
, plus potentially one or moreshort-lived objects to build the merged context each time the logger is
invoked at or above its configured level.
For example, our
Input::Base
could implement it as follows, enabling eachlog message to include helpful metadata about the pipeline and the plugin to
differentiate each instance, without changes to the plugins themselves:
From here, any invocation of the logger within any input would include this context:
And any invocation that occurred while handling an exception could
automatically include the exception's message and backtrace, potentially
mirroring the pattern that is frequently used:
I have a quick-and-dirty ruby implementation of this logger_context_proxy,
and would appreciate conceptual feedback, as well as ideas of where this could
fit in with the current javafication.
The text was updated successfully, but these errors were encountered: