Amend logging to capture the class which is making the log statement

Hi All,

In our implementation we are logging debug statements/requets/responses at various places. We do it from BasePageBean base class method which calls LogUtils ((this.log(“Sample text”)).

But the pattern printed by this statement doesnt print the class that is actually printing the log statement. This pattern is governed by “logging.properties” file. I changed the file to add %C and %L in the pattern like below:

log4j.message.pattern=%d{yyyy-MM-dd HH:mm:ss z} %x (%C : %L) - %m%n
But looks like this logging utility is kind of a wrapper class and the following class is printed always:

(com.webMethods.caf.faces.util.LogUtils : 129)- ..*. Test Logging statement

Generally logging libraries/wrappers allow us to pass a classname and level to the log() method such that the calling class and level can be controlled, however from what we can see here is even if we call LogUtils class directly we cannot pass classname of the calling class (only log level).

Is there any way to pass or print the class name?

We are using webMethods 7.1.3

You can just use the log4j APIs directly instead of using LogUtil so the log category is the class name.

For example:


private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(getClass());
	
public void myMethod() {
	logger.warn("Hello Logger World");
}

Hi Eric,

Thanks for the Reply. We have considered this option but changing the existing code will require a huge amount of effort.

Is there anything that we can change in configuration?

Thanks andRegards,
Ninad Patil

No.

Per the javadocs of LogUtil, the log messages from that class go to a log category named “JSF”. If you want the log messages to go to a different category you would have to use a different logging API.

[url]http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuites/wmsuite7/My_webMethods/7-2_CAF_and_MWS_Java_API_Reference/com/webmethods/caf/faces/util/LogUtils.html[/url]