<div dir="ltr"><p>Hi,<br>
I am using Jetty webserver and logback for logging.</p><p><br>
I have a scenario with multiple Web Applications (so multiple wars into jetty/webapps dir). Each war has its own copy of logback-classic, logback-core and slf4j-api. There is a common copy of logback.xml in jetty/resources (pasted below). My intent is to maintain a logfile named "testapp.<date>.log" which should be used by all the wars for logging. Further, I want a rollover of this file on every startup. I am able to achieve this except that each war is trying to create its own version of the log file so when each war is loaded it creates its own logfile archiving the earlier logfile created by the earlier war. This continues till all wars are loaded thus creating these many log files per startup. The archived files are are named "testapp.<date>.log.<time in millisec>.<br>
</p>
<p>Is there a way to ask all wars to log into the same file?</p><p><br></p><p><u><b>logback.xml file content:</b></u></p><p><i><configuration><br> <timestamp key="dateStr" datePattern="yyyy-MM-dd" timeReference="contextBirth"/>--><br>
<timestamp key="timeStr" datePattern="HHmmssSSS" timeReference="contextBirth"/>--><br><br> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"><br>
<encoder><br> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern><br> </encoder><br> </appender><br> <br> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><br>
<file>${jetty.home}/logs/Baywatch.${dateStr}.log</file><br><br> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><br> <!-- daily rollover --><br> <fileNamePattern>${jetty.home}/logs/Baywatch.%d{yyyy-MM-dd}.log.${timeStr}</fileNamePattern><br>
<br> <!-- keep max 30 rolled over files --><br> <maxHistory>30</maxHistory><br> <cleanHistoryOnStart>true</cleanHistoryOnStart><br><br> <!-- Baywatch trigger for daily rollover and every server restart --><br>
<timeBasedFileNamingAndTriggeringPolicy class="com.bmc.ola.utils.<b>LogbackLogTriggeringPolicy</b>"/><br> </rollingPolicy><br><br> <encoder><br> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern><br>
</encoder><br> </appender><br> <br> <root level="INFO"><br> <appender-ref ref="FILE" /><br> </root><br></configuration></i></p><p><br></p><p><b>LogbackLogTriggeringPolicy.java is:</b></p>
<p><i>@NoAutoStart<br>public class LogbackLogTriggeringPolicy<E> extends DefaultTimeBasedFileNamingAndTriggeringPolicy<E> {<br> @Override<br> public void start() {<br> super.start();<br> nextCheck = 0L;<br>
addInfo("gktest123");<br> isTriggeringEvent(null, null);<br> try {<br> tbrp.rollover();<br> } catch (RolloverFailure e) {<br> //Do nothing<br> }<br>
}<br>}<br></i></p><p>Thanks.<br></p>
</div>