Reputation: 6200
I am trying to upgrade log4j to log4j2. The particular line of code I am trying to upgrade is:
log(targetClass, Priority.DEBUG_INT, message, null);
The static field Priority.DEBUG_INT
is no longer available in the new Priority
. Instead it looks like the getPriority(Facility facility, org.apache.logging.log4j.Level level)
static method is used to access priority int value, to which DEBUG
can be specified as the Level
.
However, this method also requires a Facility
to be specified. How do I know which Facility
to specify when calling getPriority
?
old Priority: https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Priority.html
new Priority: https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/net/Priority.html
new Facility: https://logging.apache.org/log4j/log4j-2.8/log4j-core/apidocs/org/apache/logging/log4j/core/net/Facility.html
Upvotes: 2
Views: 2894
Reputation: 6884
Assuming you are talking about Log4j 1's Category.log(String, Priority, Object, Throwable)
, it appears these Priority
classes are pretty (if not completely) unrelated. Log4j 1's Priority
is actually the level (indeed it has a subclass Level
).
So you would have to look at Log4j 2's Logger
class to see if any method with Level
parameter matches, but there appears to be no identical alternative (except logMessage
maybe, but that appears to be pretty low level).
However, you should check whether that targetClass
argument for parameter callerFQCN
is actually needed. It looks like it is intended to find the caller of the logger method and might mainly be intended for usage by logging libraries extending Log4j 1. Unless you are indeed upgrading such library, I would assume that the method is misused and a regular Log4j 2 logger.debug(message)
would do equally well. Though it would help nonetheless if you could provide more context.
Upvotes: 1