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

RetainingAppender does not persist lazily-initialized log context #98

Open
filipovskid opened this issue Sep 4, 2024 · 1 comment · May be fixed by #99
Open

RetainingAppender does not persist lazily-initialized log context #98

filipovskid opened this issue Sep 4, 2024 · 1 comment · May be fixed by #99

Comments

@filipovskid
Copy link

filipovskid commented Sep 4, 2024

Description

When buffering ILoggingEvent log events, the RetainingAppender does not persist the event's lazily-initialized fields, such as the MDC (Mapped Diagnostic Context) and thread name. As a result, when the retained logs are eventually dumped, these fields are initialized to the current context rather than the context at the time the log event was created. This behavior leads to incorrect log information, which can cause confusion and misinterpretation of log data.

Steps to Reproduce:

  1. Configure Logback with a RetainingAppender that buffers log events and pipes/dumps them to an Appender that does not invoke ILoggingEvent#prepareForDeferredProcessing.
    1.1. Alternative: Since it is easiest to test with a ConsoleAppender, which does prepare the event for deferred processing, another way to reproduce the issue is to only log events whose level is below the threshold and finally trigger an event that dumps the buffer.
  2. Log multiple entries while updating the MDC between each log.
  3. Trigger an event that causes the RetainingAppender to flush the buffered logs.
    Result: The flushed log events will incorrectly reflect the current MDC context rather than the context at the time each event was logged.

I will provide a test case in the upcoming PR that reproduces this issue.

Solution

Invoke ILoggingEvent#prepareForDeferredProcessing() before buffering the log event. According to the documentation, this method should be called to ensure context data like MDC and thread name are properly captured for asynchronous or deferred logging.

@filipovskid
Copy link
Author

I will open a PR shortly.

filipovskid pushed a commit to filipovskid/girders that referenced this issue Sep 4, 2024
…are present in the Logback's logger tree

* Currently, the ROOT logger has a ConsoleAppender attached, which introduces side effects affecting the RetainingAppender tests
filipovskid pushed a commit to filipovskid/girders that referenced this issue Sep 4, 2024
@filipovskid filipovskid linked a pull request Sep 4, 2024 that will close this issue
filipovskid pushed a commit to filipovskid/girders that referenced this issue Sep 4, 2024
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 a pull request may close this issue.

1 participant