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

[WIP] Use jcabi-log to reduce startup time #3015

Closed
wants to merge 22 commits into from
Closed

[WIP] Use jcabi-log to reduce startup time #3015

wants to merge 22 commits into from

Conversation

koppor
Copy link
Member

@koppor koppor commented Jul 15, 2017

This implements #2966 (comment):

Logger.debug(this, ...) instead of LOGGER.debug(...)

13:56:54.678 [AWT-EventQueue-0] INFO org.jabref.logic.importer.OpenDatabase - Opening: C:\git-repositories\jabref\jabref\src\test\resources\testbib\complex.bib

#3017 is also included here, because of net.corda:jfx depends on org.slf4j:jcl-over-slf4j, but we want to pipe slf4j to jcl.

@tobiasdiez Could you check the startup time?

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
  • If you changed the localization: Did you run gradle localizationUpdate?

@koppor koppor force-pushed the jcabi-log branch 2 times, most recently from 4045be0 to ab9a710 Compare July 15, 2017 11:59
@koppor koppor changed the title [WIP] Use jcabi-log to reduce startup time Use jcabi-log to reduce startup time Jul 15, 2017
@koppor koppor requested a review from tobiasdiez July 15, 2017 12:02
@koppor koppor added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 15, 2017
@koppor koppor requested a review from lenhard July 15, 2017 12:02
Copy link
Member

@lenhard lenhard left a comment

Choose a reason for hiding this comment

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

The jcabi log framework is new to me and I have nothing against reworking our current logging implementation. As far as I can see it saves us the declaration of the static variable, with is clearly a benefit. But does it actually improve something performance-wise? Because as far as I understand, it's just a wrapper for slf4j and then I don't see why it should be faster. But anyway, the readability improvement is probably worth it already.

Nevertheless, you have a few failing tests here. Do these fail because of logging? They need to succeed before we can merge.

Finally, when I look at the blog post where the framework is introduced: http://www.yegor256.com/2014/05/23/avoid-java-static-logger.html and scroll to the comments, I can find one by our good friend @simonharrer, who recommends this: http://www.tinylog.org/ I can't really find a comparison between jcabi and tinylog, but if I understand it correctly then tinylog will use just one logger and nothing class-based (which seems to be something that we want).

TL&DR: I want to know how this affects performance. Otherwise, fix the failing tests and then it's mergeable.

@koppor koppor changed the title Use jcabi-log to reduce startup time [WIP] Use jcabi-log to reduce startup time Jul 16, 2017
@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 16, 2017
@koppor
Copy link
Member Author

koppor commented Jul 16, 2017

Rumors said that simonharrer uses jcabi-log in current projects. 😇

Without this PR

10% time for logging startup

grafik

With this PR

7% time for logging startup

grafik

@koppor
Copy link
Member Author

koppor commented Jul 17, 2017

@lenhard You are right, the logging of exceptions changed (not that obviously documented - see jcabi/jcabi-log#68).

Logger.debug("Error during X", e);

becomes

Logger.debug("Error during X: %[exception]s", e);

I began to rewrite our code, but I am unsure whether we really want that. Maybe we should write our own static log methods which check whether the last parameter is instance of Throwable, add : %[exception]s to the formatting string, and finally delegate to jcabi-log?

@lenhard
Copy link
Member

lenhard commented Jul 17, 2017

3% improvement is an improvement, so we should go for it :)

Regarding the exception: I think the way you suggest is the right one. You should write a wrapper class, say org.jabref.JabRefLogger with static methods for the different log levels and one for an exception. Then this logger should be used in JabRef. Otherwise we would be duplicating %[exception]s all over the code

@Siedlerchr
Copy link
Member

Yes, but instead of checking explicitly for a throwable, just create one wrapper method overlaod which excepts an Throwable as second argument.

@koppor
Copy link
Member Author

koppor commented Jul 19, 2017

Done. See org.jabref.Logger. We still (?) have many classes with static methods. 0c0d26b#diff-f64d223f20f6b0e53b00c8dbd2be2ce1R62 I cannot fix that, but just ignore them in the ArchitectureTests.

@koppor koppor changed the title [WIP] Use jcabi-log to reduce startup time Use jcabi-log to reduce startup time Jul 19, 2017
@koppor koppor added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 19, 2017
/** begin: direct pass-through **/

public static void trace(final Object source, final String msg) {
com.jcabi.log.Logger.trace(source, msg);
Copy link
Member

Choose a reason for hiding this comment

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

Why don't you import this package or will it provide conflicsts with the local class named Logger?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there would be conflicts.

@stefan-kolb
Copy link
Member

Not sure if changing the interface of such a well-known functionality like logging is really the way to go. Don't you think this will lead to fragmented code as not everyone is used to it?

Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

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

Replace the array concat with Guava, the rest LGTM

* Merges args and e together into an array starting with args
*/
private static Object[] merge(Object[] args, Throwable e) {
final int length = args.length;
Copy link
Member

Choose a reason for hiding this comment

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

@@ -0,0 +1,7 @@
# Architectural Decision Records

This lists the architectural decisions for Eclipse Winery™
Copy link
Member

Choose a reason for hiding this comment

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

Stuff from Winery....

@koppor
Copy link
Member Author

koppor commented Jul 19, 2017

I agree that this is uncommon. However, I think (i) it is more convenient to work without Logger factory, if one wants "gschwind mal was loggen". (ii) We have the architecture test in place complaining if someone uses apache commons logging 😇 .

@lenhard
Copy link
Member

lenhard commented Jul 19, 2017

Why is there a problem with using the Logger in static methods? Because you need to provide an instance as the source of the message? If that's the case, why don't you just do something like this: Logger.debug(MyClass.class, "My log message");

The style of logging should be the same everywhere, in static and non-static methods. If we can't find a uniform way, logging will just degrade over time and we end up with a mess.

@koppor
Copy link
Member Author

koppor commented Jul 19, 2017

jcabi-log needs this, because it also provides information on threads. See here for more features: http://log.jcabi.com/

In case we don't want to have this feature, I can rewrite the layer so that this does not need passed. Think, then we are at TinyLog. I'm unsure, why we dropped that in another project...

@lenhard
Copy link
Member

lenhard commented Jul 19, 2017

Hm, how about at least adding a few methods to the current solution that does not require this? So that we can use the new logger also from static methods. That would be a compromise (we get the threading information if we want, but we don't have to). What do zou think? Would that work?

@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jul 20, 2017
@koppor koppor changed the title Use jcabi-log to reduce startup time [WIP] Use jcabi-log to reduce startup time Jul 20, 2017
@stefan-kolb
Copy link
Member

I'd still favor keeping the current logging. I don't see too much improvements and a few problems with the new solution.

@koppor
Copy link
Member Author

koppor commented Jul 21, 2017 via email

@koppor
Copy link
Member Author

koppor commented Aug 10, 2017

We do NOT want to change the usual way of doing logging for just saving some seconds at the startup time.

@koppor koppor mentioned this pull request Jun 11, 2018
6 tasks
@koppor
Copy link
Member Author

koppor commented Nov 2, 2020

If I redid this, I would give tinylog a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants