java - log4j how I can get FileAppender's name with log4j..getRootLogger() -
i use log4j.getrootlogger().getappender("ficwarn")
in java code, can't path of fileappender.
how can name of file messages written ?
it file defined in log4j.propertiers or log4j.xml.
better log this:
private static final logger = loggerfactory.getlogger(classname.class); // or specific channels private static final logger = loggerfactory.getlogger("ficwarn");
now define appender in log4j
<?xml version="1.0" encoding="utf-8" ?> <!doctype log4j:configuration system "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="console" class="org.apache.log4j.consoleappender"> <param name="target" value="system.out"/> <layout class="org.apache.log4j.patternlayout"> <param name="conversionpattern" value="%-5p %c{1} - %m%n"/> </layout> </appender> <appender name="ficwarn" class="org.apache.log4j.rollingfileappender"> <param name="file" value="ficwarn.log"/> <param name="maxfilesize" value="100kb"/> <!-- keep 1 backup file --> <param name="maxbackupindex" value="1"/> <layout class="org.apache.log4j.patternlayout"> <param name="conversionpattern" value="%p %t %c - %m%n"/> </layout> </appender> <logger name="ficwarn"> <level value="info"/> <appender-ref ref="ficwarn" /> </logger> <root> <priority value ="debug" /> <appender-ref ref="console" /> </root> </log4j:configuration>
now messages go either console (classname) or ficwarn.log (string = "ficwarn").
Comments
Post a Comment