You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Ashish Kulkarni <as...@gmail.com> on 2009/01/30 23:09:40 UTC
Find log file name and appender in Java Program
HiI need to find out the log file name, and path in Java program,
I tried
logger.getAppender("A1").getName()
and also
Enumeration enu = Logger.getRootLogger().getAllAppenders();
I need to retrieve /app/logs/mylog/log4jXml.xml in my java program
But is it not returning the appender,
my log4j.xml file is as below
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="A1"
class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="/app/logs/mylog/log4jXml.xml" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.xml.XMLLayout">
</layout>
</appender>
<category name="myclass">
<priority value="debug" />
<appender-ref ref="A1" />
</category>
<root>
<priority value="INFO" />
<appender-ref ref="STDOUT" />
</root>
</log4j:configuration>
Re: Find log file name and appender in Java Program
Posted by Curt Arnold <ca...@apache.org>.
Once you have a generic Appender object, which could be any one of a
number of appender types, many of which do not have file names, you
should test whether it is an instance of FileAppender and then call
the getFile() method.
if (logger.getAppender("A1") instanceof FileAppender) {
String file = ((FileAppender) logger.getAppender("A1")).getFile();
}
On Jan 30, 2009, at 4:09 PM, Ashish Kulkarni wrote:
> HiI need to find out the log file name, and path in Java program,
> I tried
> logger.getAppender("A1").getName()
I would think would return "A1" since that is the name of the appender.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org