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

CompositeJsonFormatter must set Context on JsonProviders BEFORE setting the JsonFactory #475

Closed
brenuart opened this issue Jan 8, 2021 · 0 comments
Labels
Milestone

Comments

@brenuart
Copy link
Collaborator

brenuart commented Jan 8, 2021

When start() is invoked, the CompositeJsonFormatter starts by creating its internal JsonFactory then assign it to the configured JsonProviders. The next step is to configure the JsonProviders with the LoggerContext and then to start them. The sequence of looks as follows:

   jsonFactory = createJsonFactory();
   jsonProviders.setJsonFactory(jsonFactory);
   jsonProviders.setContext(context);
   jsonProviders.start();

Unfortunately, some providers like the AbstractPatternJsonProvider start parsing their pattern immediately when the JsonFactory is set instead of waiting until they are actually started (see AbstractPatternJsonProvider.java#L73). This means that no context is available to them to report parsing errors.

A comment in the AbstractPatternJsonProvider says that parsing must be done when the JsonFactory is set and not during start() because the latter is invoked by logstash's XML parser "too early" before the formatter had a chance to set the JsonFactory.

According to this last comment, it seems obvious that the CompositeJsonFormatter must set the context on the providers BEFORE setting the JsonFactory.


Note: everything works nicely when Logback is configured via an XML configuration file because logback takes care of setting the context on every components it creates. The context is therefore already set when the JsonFactory is injected by the CompositeJsonFormatter.
Things are getting more tricky when one configures logback programmatically... If I rely on the CompositeJsonFormatter to propagate and set the context the providers, everything will work except errors will never be reported.

@philsttr philsttr added this to the 7.0 milestone Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants