Do not use Apache Tomcat org.apache.juli.logging

This rule detects the usage of the org.apache.juli.logging.Log and org.apache.juli.logging.LogFactory classes and methods. These logging methods are not available in WebSphere traditional or Liberty and must be migrated.

When an automated fix becomes available It will replace the org.apache.juli.logging.LogFactory with java.util.logging.Logger . It also replaces the Apache Tomcat logging methods with the Java Logger.log(Level, message) method.

Some of the Apache Tomcat methods map directly to a defined java.util.logging.Level . For the levels that do not map directly, you can customize the log level in the Analysis Configuration dialog.

The automated fix replacements are shown in this mapping table. Log methods that pass a Throwable as a second parameter are mapped in the same manner as their counterparts in the following table.

org.apache.juli.logging method java.util.logging method Configurable
LogFactory.getLog(Class.class) Logger.getLogger(Class.class.getName()) No
LogFactory.getLog("log name") Logger.getLogger("log name") No
LogFactory.getInstance(Class.class) Logger.getLogger(Class.class.getName()) No
LogFactory.getInstance("log name") Logger.getLogger("log name") No
Log.fatal("mgs") Logger.log(WsLevel.FATAL, "msg") Yes
Log.error("msg") Logger.log(Level.SEVERE, "msg") Yes
Log.warn("msg") Logger.log(Level.WARNING, "msg") No
Log.info("msg") Logger.log(Level.INFO, "msg") No
Log.debug("msg") Logger.log(WsLevel.DETAIL, "msg") Yes
Log.trace("msg") Logger.log(Level.FINE, "msg") Yes

For example, log class instance creation:

Log log = LogFactory.getLog(MyClass.class);

is migrated to
Logger log = Logger.getLogger(MyClass.class.getName());

This example shows a call to org.apache.juli.logging.Log.error() with a Throwable as the second parameter.

catch (Exception e) {
log.error("Some error message", e);
}

The example is migrated to the following code:
catch (Exception e) {
log.log(Level.SEVERE, "Some error message", e);
}


Notes:
  1. Some of the log method migrations are configurable. For example, if you want the Log.trace method to be migrated to a level other than WsLevel.DETAIL , you could change it in the Analysis Configuration dialog box.
  2. WsLevel is defined in the IBM(R) class, com.ibm.websphere.logging.WsLevel . It extends java.util.logging.Level to provide additional log levels. If you do not want to use the WsLevel defined levels, you can also configure those mappings in the Analysis Configuration dialog box under this Tomcat Java rule.
  3. Not all LogFactory methods are migrated. You may have additional manual migration to do after the basic logging methods are migrated. Evaluate any additional use of LogFactory methods in your application.
  4. The methods in the org.apache.juli.logging.Log class have parameters of type java.lang.Object. The methods in the java.util.logging.Logger class have parameters of type java.lang.String. If you use parameters with types other than java.lang.String, you might need to do additional manual migration to add toString() to the parameters after running the automated fix will migrate from org.apache.juli.logging.Log to java.util.logging.Logger.

For additional information, see the following Java documentation: