logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From levtbinh <bryan...@mail.rakuten.com>
Subject [Log4j2] How to change the appender file name at run time
Date Mon, 22 Jul 2013 03:38:50 GMT
In my application, I would want to save log of different sources to different
files without knowing the file names before hand.

How should I do that with Log4j2?

I have tried the following config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <properties>
        <property name="logDir">/home/ad/log</property>
        <property name="pattern">%d{yyyy-MM-dd HH:mm:ss.SSS} | %-5.5p |
%-10.10t | %C:%-5.5L | %msg%n</property>
    </properties>
    <appenders>
        
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="${pattern}"/>
        </Console>
        
        
        <File name="Debug" fileName="${sys.logFileName}">
            <PatternLayout>
                <pattern>${pattern}</pattern>
            </PatternLayout>
        </File>
        <File name="Product" fileName="${sys.logFileName}">
            <PatternLayout>
                <pattern>${pattern}</pattern>
            </PatternLayout>
        </File>
    </appenders>
    <loggers>
        <logger name="productLogger" level="INFO" additivity="false">
            <appender-ref ref="Product"/>
        </logger>
        <logger name="debugLogger" level="DEBUG" additivity="false">
            <appender-ref ref="Console"/>
            <appender-ref ref="Debug"/>
        </logger>
        
        <root level="info"> 
            <appender-ref ref="Console"/> 
        </root>
    </loggers>
</configuration>

And tried to set the sys.logFileName property in the code but it doesn't
work

System.setProperty("logFileName", fileName);
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
ctx.reconfigure();

Thank you.




--
View this message in context: http://apache-logging.6191.n7.nabble.com/Log4j2-How-to-change-the-appender-file-name-at-run-time-tp39025.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message