Jetty: How to get multiple web applications log to a common log file

Hi, I am using Jetty webserver and logback for logging. 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>. Is there a way to ask all wars to log into the same file? *logback.xml file content:* *<configuration> <timestamp key="dateStr" datePattern="yyyy-MM-dd" timeReference="contextBirth"/>--> <timestamp key="timeStr" datePattern="HHmmssSSS" timeReference="contextBirth"/>--> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${jetty.home}/logs/Baywatch.${dateStr}.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <fileNamePattern>${jetty.home}/logs/Baywatch.%d{yyyy-MM-dd}.log.${timeStr}</fileNamePattern> <!-- keep max 30 rolled over files --> <maxHistory>30</maxHistory> <cleanHistoryOnStart>true</cleanHistoryOnStart> <!-- Baywatch trigger for daily rollover and every server restart --> <timeBasedFileNamingAndTriggeringPolicy class="com.bmc.ola.utils. LogbackLogTriggeringPolicy"/> </rollingPolicy> <encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender> <root level="INFO"> <appender-ref ref="FILE" /> </root> </configuration>* *LogbackLogTriggeringPolicy.java is:* *@NoAutoStart public class LogbackLogTriggeringPolicy<E> extends DefaultTimeBasedFileNamingAndTriggeringPolicy<E> { @Override public void start() { super.start(); nextCheck = 0L; addInfo("gktest123"); isTriggeringEvent(null, null); try { tbrp.rollover(); } catch (RolloverFailure e) { //Do nothing } } } * Thanks.

Hi, [Please ignore the previous email with the same subject line. That was accidentally posted.] I am using Jetty webserver and logback for logging. 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>. Is there a way to ask all wars to log into the same file? *logback.xml file content:* *<configuration> <timestamp key="dateStr" datePattern="yyyy-MM-dd" timeReference="contextBirth"/>--> <timestamp key="timeStr" datePattern="HHmmssSSS" timeReference="contextBirth"/>--> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${jetty.home}/logs/testapp.${dateStr}.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <fileNamePattern>${jetty.home}/logs/testapp.%d{yyyy-MM-dd}.log.${timeStr}</fileNamePattern> <!-- keep max 30 rolled over files --> <maxHistory>30</maxHistory> <cleanHistoryOnStart>true</cleanHistoryOnStart> <!-- trigger for daily rollover and every server restart --> <timeBasedFileNamingAndTriggeringPolicy class="utils. LogbackLogTriggeringPolicy"/> </rollingPolicy> <encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender> <root level="INFO"> <appender-ref ref="FILE" /> </root> </configuration>* *LogbackLogTriggeringPolicy.java is:* *@NoAutoStart public class LogbackLogTriggeringPolicy<E> extends DefaultTimeBasedFileNamingAndTriggeringPolicy<E> { @Override public void start() { super.start(); nextCheck = 0L; isTriggeringEvent(null, null); try { tbrp.rollover(); } catch (RolloverFailure e) { //Do nothing } } } * Thanks.

any suggestions will be really appreciated. I am totally stuck on this. On Tue, Oct 30, 2012 at 11:39 PM, Gaurav Kumar <gaurav419@gmail.com> wrote:
Hi,
[Please ignore the previous email with the same subject line. That was accidentally posted.]
I am using Jetty webserver and logback for logging.
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>.
Is there a way to ask all wars to log into the same file?
*logback.xml file content:*
** *<configuration> <timestamp key="dateStr" datePattern="yyyy-MM-dd" timeReference="contextBirth"/>--> <timestamp key="timeStr" datePattern="HHmmssSSS" timeReference="contextBirth"/>-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> * * <file>${jetty.home}/logs/testapp.${dateStr}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover -->
<fileNamePattern>${jetty.home}/logs/testapp.%d{yyyy-MM-dd}.log.${timeStr}</fileNamePattern>
<!-- keep max 30 rolled over files --> <maxHistory>30</maxHistory> <cleanHistoryOnStart>true</cleanHistoryOnStart>
<!-- trigger for daily rollover and every server restart --> <timeBasedFileNamingAndTriggeringPolicy class="utils. LogbackLogTriggeringPolicy"/>
</rollingPolicy>
<encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender>
<root level="INFO"> <appender-ref ref="FILE" /> </root> </configuration> *
*LogbackLogTriggeringPolicy.java is:*
** *@NoAutoStart public class LogbackLogTriggeringPolicy<E> extends DefaultTimeBasedFileNamingAndTriggeringPolicy<E> { @Override public void start() { super.start(); nextCheck = 0L; * * isTriggeringEvent(null, null); try { tbrp.rollover(); } catch (RolloverFailure e) { //Do nothing } } } *
Thanks.

With each application having its own copy of slf4j and logback you are making it so each web app will have to have its own appenders writing to the file. While Logback supports using prudent mode for this, I don't recommend it. Instead, I would suggest that you move logback and slf4j out of the web apps an add them to a common classpath and then have them share the logging configuration. With that you should have no problem having multiple web apps write to the same file. On Oct 31, 2012, at 5:56 AM, Gaurav Kumar wrote:
any suggestions will be really appreciated. I am totally stuck on this.
On Tue, Oct 30, 2012 at 11:39 PM, Gaurav Kumar <gaurav419@gmail.com> wrote: Hi, [Please ignore the previous email with the same subject line. That was accidentally posted.]
I am using Jetty webserver and logback for logging.
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>. Is there a way to ask all wars to log into the same file?
logback.xml file content:
<configuration> <timestamp key="dateStr" datePattern="yyyy-MM-dd" timeReference="contextBirth"/>--> <timestamp key="timeStr" datePattern="HHmmssSSS" timeReference="contextBirth"/>-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${jetty.home}/logs/testapp.${dateStr}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <fileNamePattern>${jetty.home}/logs/testapp.%d{yyyy-MM-dd}.log.${timeStr}</fileNamePattern>
<!-- keep max 30 rolled over files --> <maxHistory>30</maxHistory> <cleanHistoryOnStart>true</cleanHistoryOnStart>
<!-- trigger for daily rollover and every server restart --> <timeBasedFileNamingAndTriggeringPolicy class="utils.LogbackLogTriggeringPolicy"/>
</rollingPolicy>
<encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender>
<root level="INFO"> <appender-ref ref="FILE" /> </root> </configuration>
LogbackLogTriggeringPolicy.java is:
@NoAutoStart public class LogbackLogTriggeringPolicy<E> extends DefaultTimeBasedFileNamingAndTriggeringPolicy<E> { @Override public void start() { super.start(); nextCheck = 0L; isTriggeringEvent(null, null); try { tbrp.rollover(); } catch (RolloverFailure e) { //Do nothing } } }
Thanks.
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

If you need a single destination for the whole web container, and you do not want to violate the servlet specification by writing to the file system, and the web container uses JDK14 logging and provide suitable logging facilities, you can use the slf4j-jdk bridge to forward the events to the web container log. In my opinion this is the correct approach for web applications. From: logback-user-bounces@qos.ch [mailto:logback-user-bounces@qos.ch] On Behalf Of Gaurav Kumar Sent: 31. oktober 2012 13:57 To: logback-user@qos.ch Subject: Re: [logback-user] Jetty: How to get multiple web applications log to a common log file any suggestions will be really appreciated. I am totally stuck on this. On Tue, Oct 30, 2012 at 11:39 PM, Gaurav Kumar <gaurav419@gmail.com> wrote: Hi, [Please ignore the previous email with the same subject line. That was accidentally posted.] I am using Jetty webserver and logback for logging. 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>. Is there a way to ask all wars to log into the same file? logback.xml file content: <configuration> <timestamp key="dateStr" datePattern="yyyy-MM-dd" timeReference="contextBirth"/>--> <timestamp key="timeStr" datePattern="HHmmssSSS" timeReference="contextBirth"/>--> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${jetty.home}/logs/testapp.${dateStr}.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <fileNamePattern>${jetty.home}/logs/testapp.%d{yyyy-MM-dd}.log.${timeStr}</f ileNamePattern> <!-- keep max 30 rolled over files --> <maxHistory>30</maxHistory> <cleanHistoryOnStart>true</cleanHistoryOnStart> <!-- trigger for daily rollover and every server restart --> <timeBasedFileNamingAndTriggeringPolicy class="utils.LogbackLogTriggeringPolicy"/> </rollingPolicy> <encoder> <pattern>%date{MMM dd}, %date{yyyy hh:mm:ss a} %class %method\(\):%line %n%level: %message%n </pattern> </encoder> </appender> <root level="INFO"> <appender-ref ref="FILE" /> </root> </configuration> LogbackLogTriggeringPolicy.java is: @NoAutoStart public class LogbackLogTriggeringPolicy<E> extends DefaultTimeBasedFileNamingAndTriggeringPolicy<E> { @Override public void start() { super.start(); nextCheck = 0L; isTriggeringEvent(null, null); try { tbrp.rollover(); } catch (RolloverFailure e) { //Do nothing } } } Thanks.
participants (3)
-
Gaurav Kumar
-
Ralph Goers
-
Thorbjørn Ravn Andersen