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

Add support for Log4j 2's ThreadContext #207

Merged
merged 2 commits into from
Mar 25, 2021
Merged

Add support for Log4j 2's ThreadContext #207

merged 2 commits into from
Mar 25, 2021

Conversation

Marcono1234
Copy link
Contributor

Resolves #188

The code orientates itself to the existing SLF4J MDC one.

Noteworthy:

Copy link
Contributor

@sjoerdtalsma sjoerdtalsma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your great work!
I did an initial review from the online github interface but will check out your branch to have a closer look from the IDE.

Please don't be overwhelmed by the number of comments; I tried to be constructive in my criticism and I like the general quality of this PR, which again is greatly appreciated!

log4j2-propagation/README.md Show resolved Hide resolved
* @param data data to apply, may be {@code null}
* @param overwrite whether all existing data should overwritten
*/
static void applyToCurrentThread(ThreadContextData data, boolean overwrite) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why package protected in a public class?
Can't the whole class be package protected in this case?

Please use an interface for the API if you don't want to expose the whole class; this makes it easier to avoid accessibility errors or misuse in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods are only intended for usage by ThreadContextManager. It might also be possible to have this logic only in ThreadContextManager, work with the public methods of ThreadContextData and have its constructor be package-private, but I felt the logic belongs closer to ThreadContextData than to ThreadContextManager.

As for why these methods are package-private: Most of them provide internal functionality already provided (indirectly) through ThreadContextManager or through Log4j 2's ThreadContext. Providing it publicly might be confusing and lead to incorrect usage.
Making the whole class package-private is not an option because it is publicly exposed through ThreadContextManager and would therefore cause usability issues when someone tries to use ThreadContextManager.

I don't think making it an interface fits really well because it is not expected that the user implements or subclasses this class. Because the package-private methods are not accessible to the user and are not shown in the javadoc either, I don't think that this is an issue.

Would it be alright for you to leave the class as is? If you want I can add a comment (not part of the documentation) to the class describing the rationale I described here.

* Represents a snapshot of the data of the Log4j 2 {@link ThreadContext} of a
* specific thread at a certain point in the past.
*/
public class ThreadContextData {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When multiple context managers are applied it may be useful to know this is Log4j2's data?
Perhaps create an interface Log4j2ThreadContext with implementation Log4j2ThreadcontextData ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if having an interface is worth it, see #207 (comment). We are not expecting the user to provide their own implementation of that class, are we?

slf4j-mdc-propagation/pom.xml Outdated Show resolved Hide resolved
@sjoerdtalsma
Copy link
Contributor

Just to touch base, I have been rather busy lately with many things on my mind.
But let me ensure you, this PR has not been forgotten by me and it's on my list of things to do.

@sjoerdtalsma
Copy link
Contributor

Could you please split this PR into the Log4j2 module only and (optionally) create separate PR's for the other concerns?
It is a bit much for me to review all in a single PR and I would like to be able to focus on the Log4j2 implementation, so we can have a clean first version.

@sjoerdtalsma
Copy link
Contributor

I'll create a PR to rename the MDC module (with a new relocation in place for it)

@Marcono1234
Copy link
Contributor Author

Could you please split this PR into the Log4j2 module only and (optionally) create separate PR's for the other concerns?

Yes, I can do that. Though if you don't mind, it would like to wait for your pull request to be merged first and then rebase this pull request onto develop.

@Marcono1234 Marcono1234 mentioned this pull request Mar 5, 2021
@Marcono1234
Copy link
Contributor Author

Sorry for the delay; I have rebased the changes onto #217 (so that should be merged first), and addressed some of your review comments (which I then marked as resolved).

@sjoerdtalsma
Copy link
Contributor

Do you want to rebase on develop again? I merged #217 just now.
I think it would be a good idea to focus on the new log4j2 module and leave all else out of this PR.

@sjoerdtalsma
Copy link
Contributor

I have some issues still, but I can work out those myself after I've merged this.
Let me thank you once more sincerely for your work and your patience with code review 😉.

@sjoerdtalsma sjoerdtalsma merged commit 545f9e8 into talsma-ict:develop Mar 25, 2021
@Marcono1234 Marcono1234 deleted the marcono1234/log4j2 branch March 28, 2021 00:35
@Marcono1234
Copy link
Contributor Author

Thanks for merging the changes!

@sjoerdtalsma
Copy link
Contributor

Thanks for merging the changes!

Thanks for contributing them!

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 this pull request may close these issues.

Add support for Log4j2's ThreadContext
2 participants