Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public Class<?> findClass(final String name) throws ClassNotFoundException {
invalidClasses.add(name);
if (DEBUG) {
LogWrapper.log(Level.TRACE, e, "Exception encountered attempting classloading of %s", name);
LogManager.getLogger("LaunchWrapper").log(Level.ERROR, "Exception encountered attempting classloading of %s", e);
LogManager.getLogger("LaunchWrapper").log(Level.ERROR, String.format("Exception encountered attempting classloading of %s", name), e);
Copy link
Contributor

Choose a reason for hiding this comment

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

This however, is fine, cuz derp.

Copy link

@jamierocks jamierocks Jan 23, 2018

Choose a reason for hiding this comment

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

Why not use the proper log4j way of doing things - basically replace %s for {}, no String#format(String) needed.

Copy link

Choose a reason for hiding this comment

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

@jamierocks There does not appear to be an interface method that takes both a Throwable and params.

Choose a reason for hiding this comment

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

I believe that log4j knows to use the last parameter as a Throwable when taking a series of other parameters; however, I cannot find a source.

Copy link

Choose a reason for hiding this comment

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

I would write it this way:

LogManager.getLogger("LaunchWrapper").error("Exception encountered attempting classloading of {}", name, e);

Internally the logger creates a FormattedMessage which can take a Throwable as the last argument:
https://logging.apache.org/log4j/log4j-2.1/log4j-api/apidocs/org/apache/logging/log4j/message/FormattedMessage.html

Copy link

Choose a reason for hiding this comment

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

Tracing through it doesn't use that constructor from the varargs method, but it does appear poke was correct as it seems to scan it at org.apache.logging.log4j.message.ParameterizedMessage#parseArguments

}
throw new ClassNotFoundException(name, e);
}
Expand Down