<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi to all, <div>i just switched to logback from log4j now and i want to change at runtime some settings contained in the logback.xml configuration file.</div><div>I have a logback.xml configuration file that looks like the following : </div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><configuration></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(75, 0, 252); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(87, 145, 145); "><property</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">name</span><span style="color: rgb(0, 0, 0); ">=</span>"defaultPattern"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(75, 0, 252); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">value</span><span style="color: rgb(0, 0, 0); ">=</span>"%d{dd/MM/yyyy HH:mm:ss.SSS} [%thread] %-5level - %msg%n"<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(87, 145, 145); ">/></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(90, 113, 200); "><span style="color: rgb(0, 0, 0); "> </span><!-- Appenders Configuration --></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(75, 0, 252); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(87, 145, 145); "><appender</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">name</span><span style="color: rgb(0, 0, 0); ">=</span>"CONSOLE"<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">class</span><span style="color: rgb(0, 0, 0); ">=</span>"ch.qos.logback.core.ConsoleAppender"<span style="color: rgb(87, 145, 145); ">></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span><target><span style="color: rgb(0, 0, 0); ">System.err</span></target></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(75, 0, 252); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(87, 145, 145); "><filter</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">class</span><span style="color: rgb(0, 0, 0); ">=</span>"com.aleroot.ErrOutFilter"<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(87, 145, 145); ">/></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span><encoder></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: rgb(87, 145, 145); "><pattern></span>${defaultPattern}<span style="color: rgb(87, 145, 145); "></pattern></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span></encoder></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span></appender></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "> <br class="webkit-block-placeholder"></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(75, 0, 252); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(87, 145, 145); "><appender</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">name</span><span style="color: rgb(0, 0, 0); ">=</span>"FILE"<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">class</span><span style="color: rgb(0, 0, 0); ">=</span>"ch.qos.logback.core.FileAppender"<span style="color: rgb(87, 145, 145); ">></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: rgb(87, 145, 145); "><file></span>aleroot.log<span style="color: rgb(87, 145, 145); "></file></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span><append><span style="color: rgb(0, 0, 0); ">true</span></append></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span><encoder></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> <span style="color: rgb(87, 145, 145); "><pattern></span>${defaultPattern}<span style="color: rgb(87, 145, 145); "></pattern></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span></encoder></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span></appender></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "> <br class="webkit-block-placeholder"></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "> <br class="webkit-block-placeholder"></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(90, 113, 200); "><span style="color: rgb(0, 0, 0); "> </span><!-- Output Configuration --></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(75, 0, 252); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(87, 145, 145); "><root</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">level</span><span style="color: rgb(0, 0, 0); ">=</span>"debug"<span style="color: rgb(87, 145, 145); ">></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span><appender-ref<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">ref</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(75, 0, 252); ">"FILE"</span><span style="color: rgb(0, 0, 0); "> </span>/></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span><appender-ref<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">ref</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(75, 0, 252); ">"CONSOLE"</span>/></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span></root></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "> <br class="webkit-block-placeholder"></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(75, 0, 252); "><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(87, 145, 145); "><logger</span><span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">name</span><span style="color: rgb(0, 0, 0); ">=</span>"mainLogger"<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">level</span><span style="color: rgb(0, 0, 0); ">=</span>"debug"<span style="color: rgb(87, 145, 145); ">></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span><appender-ref<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">ref</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(75, 0, 252); ">"FILE"</span><span style="color: rgb(0, 0, 0); "> </span>/></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "><span style="color: rgb(0, 0, 0); "> </span><appender-ref<span style="color: rgb(0, 0, 0); "> </span><span style="color: rgb(143, 2, 144); ">ref</span><span style="color: rgb(0, 0, 0); ">=</span><span style="color: rgb(75, 0, 252); ">"CONSOLE"</span>/></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "></logger></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; "> <br class="webkit-block-placeholder"></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(87, 145, 145); "></configuration></div></div><div><br></div><div><br></div><div>i want to change the file property of the FILE appender at runtime and add a DatePattern to the filename, i've tried with this code : </div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(246, 27, 26); ">LoggerContext<span style="color: rgb(0, 0, 0); "> lc = (</span>LoggerContext<span style="color: rgb(0, 0, 0); ">) </span>LoggerFactory<span style="color: rgb(0, 0, 0); ">.getILoggerFactory();</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space: pre; "> </span> ch.qos.logback.classic.<span style="color: rgb(246, 27, 26); ">Logger</span> logbackLogger = lc.getLogger(<span style="color: rgb(75, 0, 252); ">"mainLogger"</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space: pre; "> </span> <span style="color: rgb(246, 27, 26); ">FileAppender</span><ILoggingEvent> fileAppender =</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "> (<span style="color: rgb(246, 27, 26); ">FileAppender</span><ILoggingEvent>) logbackLogger.getAppender(<span style="color: rgb(75, 0, 252); ">"FILE"</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space: pre; "> </span> <span style="color: rgb(142, 6, 104); ">if</span>(fileAppender != <span style="color: rgb(142, 6, 104); ">null</span>) {</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space: pre; "> </span> fileAppender.stop();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(75, 0, 252); "><span class="Apple-style-span"><span style="color: rgb(0, 0, 0); "><span class="Apple-tab-span" style="white-space: pre; "> </span> fileAppender.setFile(</span>"</span><span class="Apple-style-span" style="color: rgb(0, 0, 0); ">aleroot</span><span class="Apple-style-span">-ddMMyyyy.log"<span style="color: rgb(0, 0, 0); ">);</span></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space: pre; "> </span> fileAppender.setContext(lc);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space: pre; "> </span> fileAppender.start();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space: pre; "> </span> }</div></div><div><br></div><div>The problem is that the file <span class="Apple-style-span" style="font-family: Monaco; font-size: 11px; ">aleroot.log is created anyway also if i have changed the filename, furthermore i get another file that is named exactly : </span><span class="Apple-style-span" style="font-family: Monaco; font-size: 11px; ">aleroot</span><span class="Apple-style-span">-ddMMyyyy.log while i want to have a filename like </span><span class="Apple-style-span" style="font-family: Monaco; font-size: 11px; ">aleroot</span><span class="Apple-style-span">-04122011.log . How can i achieve that ? </span></div><div><span class="Apple-style-span"><br></span></div><div><span class="Apple-style-span">Is there a settings to avoid that the log file will be created at the </span><span class="Apple-style-span" style="color: rgb(246, 27, 26); font-family: Monaco; font-size: 11px; ">LoggerFactory</span><span class="Apple-style-span" style="color: rgb(246, 27, 26); font-family: Monaco; font-size: 11px; "><span style="color: rgb(0, 0, 0); ">.getLogger(</span></span><span class="Apple-style-span" style="color: rgb(246, 27, 26); font-family: Monaco; font-size: 11px; "><span style="color: rgb(75, 0, 252); ">"mainLogger"</span></span><span class="Apple-style-span" style="color: rgb(246, 27, 26); font-family: Monaco; font-size: 11px; "><span style="color: rgb(0, 0, 0); ">)</span></span> call ? I want that the log file will be created only the first time that i write into the log files, there is no need to create an empty log file .</div><div>The log file should be created the first time that i log something to the log, for example at the first logger.debug("Something.log") , Is there a settings to achieve that ? </div><div><span class="Apple-style-span"><br></span></div><div><span class="Apple-style-span">Thanks.</span></div><br></body></html>