-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
LOG4J2-2899: Fix log4j-1.2-api LogEventWrapper thread data accessors #390
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
Conversation
@rgoers, I'd appreciate your feedback on this change when you have time. I'm primarily interested in whether or not you think it's reasonable to replace If the cross-thread check is a requirement, I think the following could work: |
Yeah, I don't think it can be guaranteed that the methods will always be called on the same thread. But I am also noticing that the method stores the thread it found but then doesn't returned it if it was cached. |
It can't be guaranteed that the original thread is still around or has the same name either, and it's expensive to look up even if it is (where the cost scales with total live threads). This becomes a question of risk tolerance and computational cost. I can keep the fallback around, I think the initial current-thread-check will handle most cases, I imagine most log4j1.2 shim users aren't using asynchronous components. |
Of course it can be guaranteed the original thread is around because most of the time the LogEventWrapper is called it will be from the same thread as the caller. Only when the caller has an AsyncAppender will that change and in that case Log4j’s AsyncAppender will have captured all the LogEvent info. To be honest, I think that code should just be calling event.getThreadName(), event.getThreadId() and event.getThreadPriority(). |
717df94
to
24bc6da
Compare
I've updated this to retain the thread-dump fallback, but use the current-thread fast path when the thread names match. I don't think the log4j 1.2 delegate in this case provides thread ID and priority accessors. My idea to use the thread bean doesn't quite work because the ThreadInfo object doesn't include priority, only the thread ID. |
24bc6da
to
53bfc21
Compare
I'm not sure why you committed this. I was just about to go modify the code to get the information from the event it is wrapping. |
Sorry Ralph, I didn't know you planned to take it over! Feel free to revert or modify, I'd be happy to review if you like. |
No. I was just going to look into it based on my last comment. But after looking at this I realized it works backwards from what I was thinking (I was thinking of the LogEventAdapter). So the changes you made are appropriate. |
No description provided.