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"?>
        <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>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="${pattern}"/>
        <File name="Debug" fileName="${sys.logFileName}">
        <File name="Product" fileName="${sys.logFileName}">
        <logger name="productLogger" level="INFO" additivity="false">
            <appender-ref ref="Product"/>
        <logger name="debugLogger" level="DEBUG" additivity="false">
            <appender-ref ref="Console"/>
            <appender-ref ref="Debug"/>
        <root level="info"> 
            <appender-ref ref="Console"/> 

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

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

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

View raw message