-
Notifications
You must be signed in to change notification settings - Fork 364
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 possibility to fetch all logged warning programmatically, see #76 #489
Conversation
Hello @syjer, I was just thinking, why not allow the user to provide a Eventually, I think of two things with "logging":
Of course, 1 is a lot of work! |
hi @danfickle
You are right! Nice idea, it will simplify some logic too. 1: yep, I'll see how many different logging messages are present. It may be a bit mechanical as a work, but I guess it will pay off. 2: agree, I guess using the builder approach + enum, we can ensure it will be possible to let the user block the execution as he want. I'll try to update the code for next week :) |
switched to the Consumer approach. Next I'll try to switch to the enum variant |
} | ||
|
||
public enum LogMessageId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think LogMessageId
will be big enough to warrant its own file.
Also, I'm worried that since we have a lot of code paths that are not tested, that we will get into trouble with mismatching argument counts for the message format. One way to alleviate this problem would be to have an message enum for each arg count and a corresponding method which accepted that enum and the correct number of args. Then we would make the enums implement a common interface, which is what the user would see. Interested in your feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree about the new file.
About the mismatching count of parameters/message, I agree we should be able to statically prevent the misuse. I'm wondering if there is an alternative way to implement it, losing the single enum type is unfortunate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, I think it will work :)
if (consumer != null) { | ||
consumer.accept(new Diagnostic(where, level, msg, th)); | ||
} | ||
} | ||
|
||
public static void cleanup() { | ||
data.remove(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to diagnosticConsumer.remove()
here to avoid zombie data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see on second thoughts that you have dealt with it using closeable of your own in apply method. Your method is probably cleaner.
openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/ThreadCtx.java
Outdated
Show resolved
Hide resolved
I've added a few inline comments, but I'm generally pleased with the look of this. My thinking was very similar. |
I've pushed some additional code following your feedback, I think it's beginning to look decent :). Btw I've added a |
You have been busy! In regards to the legacy logging situation, I think the core problem is that Therefore, I'm thinking that we work on the slf4j logger module (to use the new parameterised log messages, will require a new interface) and recommend that people use it. Of course, users can continue to use P.s. if we stick with an old version of slf4j, users can exclude our copy via maven, as it is supposedly binary backwards compatible. |
yep. I'm organizing the code to have 0 overhead for slf4j. I'm hoping to complete the PR this week :) |
I've pushed the diagnostic bridging implementation: A default one: 69fb5f5#diff-14a42331e2299f386db6d8cc423d57c8R39 And a custom one for slf4j: |
I think I got everything now :). |
after the merge of #507 I need to resolve some conflicts, I'll do it today :) |
One thing I've just noticed, the Other than that it all looks excellent online, but I will have a look on my ide after you fix merge issues. P.s. I appreciate the massive amount of work in this pr, so another big thanks. |
I guess I forgot to cover that case. I'll update there too.
You're welcome :) |
In the last commit e705452 I've propagated the With that I think we have covered all the cases? |
Yes, I think that is everything. Thanks again. |
Making slf4j-api provided scope should reduce dependency hell for end users as almost all will already have slf4j-api on their classpath. Also added a couple of manual tests to make sure module is working as expected.
thank you for the review and merging 👍 . I'll most likely do another round of cleanup as I think there is still some old unused code and pattern that can be improved using java8 api. |
Hi @danfickle , this PR is still a work in progress, but the main functionality should be here.
As you described in the issue #76 (#76 (comment)) , adding a way to fetch all logged values programmatically is quite a nice feature, this PR enable that.
I still need to do:
What do you think ? :)