Radagast the Brown
Radagast the Brown

Reputation: 3346

jetty log per context

I'm running few applications in a jetty server, each application has it's own context file in the /contexts folder, and each application specifies it's own log file.

When starting jetty, all applications are started, and working, all the log files are created, however - the all the output is emitted to the last log-file that was created, where the others stay empty.

The part that describes the logging for every context looks as follows. I tried to make sure that each context has it's own ids, and names - but still - the problem remains.

  <New id="oGMRLog2" class="java.io.PrintStream">
    <Arg>
      <New class="org.mortbay.util.RolloverFileOutputStream">
        <Arg><SystemProperty name="jetty.home" default="."/>/testlogs/std2.yyyy_mm_dd.log</Arg>
        <Arg type="boolean">false</Arg>
        <Arg type="int">90</Arg>
        <Arg><Call class="java.util.TimeZone" name="getTimeZone"><Arg>GMT+2</Arg></Call></Arg>
        <Get id="oGM2ReqLogName" name="datedFilename"/>
      </New>
    </Arg>
  </New>
  <Call class="org.mortbay.log.Log" name="info"><Arg>Redirecting GM stderr/stdout to <Ref id="oGM2ReqLogName"/></Arg></Call>
  <Call class="java.lang.System" name="setErr"><Arg><Ref id="oGMRLog2"/></Arg></Call>
  <Call class="java.lang.System" name="setOut"><Arg><Ref id="oGMRLog2"/></Arg></Call>

I start to suspect that the problem is in class="java.lang.System", where the print stream should be attached to this context alone, and not to the entire JVM

Can anybody show me what is the right way to do it?

Upvotes: 1

Views: 978

Answers (1)

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49462

(Web) Context based logging can be accomplished configuring Jetty to using Slf4j + Logback, then configuring logback with the SiftingAppender configuration, that uses information from a MDCHandler to sift according to context of the deployed webapp.

It is documented at http://wiki.eclipse.org/Jetty/Tutorial/Sifting_Logs_with_Logback

There is even a sample project showing this in action available at https://github.com/jetty-project/jetty-and-logback-example

Upvotes: 2

Related Questions