Java – get the class name of the logging record

To log errors for a given class, I am accessing the class name:

private static final String CLASS_NAME = MyClass.class.getName();
logger.error("Error occurred in "+CLASS_NAME);

Solution

You can log 4J XML itself sets record parameters

For exp –

<appender name="swcd-web" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="Threshold" value="DEBUG"/>
    <param name="Append" value="true"/>
    <param name="File" value="${catalina.home}/logs/swcd-web.log"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
    </layout>
</appender>

It will be on swcd web Record such exceptions in the log file –

2012-05-23 16:34:51,632 [main] ERROR com.idc.sage.sso.dynamo.SsoDbStorage - cannot get configuration for max SSO age
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>