blob: b185fcdb12624e584b84f5d36fa589a21eca4596 [file] [log] [blame]
<html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>(Trace) Logging</title><meta content="DocBook XSL Stylesheets V1.76.0" name="generator"><link rel="home" href="index.html" title="Virgo User Guide"><link rel="up" href="ch11.html" title="Chapter&nbsp;11.&nbsp;Serviceability and Diagnostics"><link rel="prev" href="ch11.html" title="Chapter&nbsp;11.&nbsp;Serviceability and Diagnostics"><link rel="next" href="ch11s03.html" title="Service Dumps"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><td align="left" width="20%"><a accesskey="p" href="ch11.html">Prev</a>&nbsp;</td><th align="center" width="60%">&nbsp;</th><td align="right" width="20%">&nbsp;<a accesskey="n" href="ch11s03.html">Next</a></td></tr></table><hr></div><div class="section" title="(Trace) Logging"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="serviceability-info-trace"></a>(Trace) Logging</h2></div></div></div><p>
The Virgo&rsquo;s (trace) logging support serves two main purposes:
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
It provides global trace files that capture high-volume information regarding the Virgo&rsquo;s internal events.
The files are intended for use by support personnel to diagnose runtime problems.
</li><li class="listitem">
It provides application trace files that contain application-generated output. This includes output generated using popular logging and
tracing APIs including the OSGi LogService, as well as output generated by calls to <code class="literal">System.out</code> and <code class="literal">System.err</code>.
These files are intended for use by application developers and system administrators. An application is defined as a scope so a single bundle will
not get its own log file unless it is a Web application Bundle or is included in a scoped plan or a par file.
</li></ul></div><p>
</p><p>
By default, the Virgo trace file is called <code class="literal">$SERVER_HOME/serviceability/logs/log.log</code>,
and, again by default, the application trace files are called <code class="literal">$SERVER_HOME/serviceability/logs/</code><span class="emphasis"><em>application_name</em></span>
<code class="literal">/log.log</code>, where <span class="emphasis"><em>application_name</em></span> is automatically set by Virgo for each application artifact
installed and run (it is a combination of the artifact name and the version).
</p><p>
The default behaviour of these trace files is that, once <code class="literal">log.log</code> reaches a 10Mb limit, it rolls into a series of files named
<code class="literal">log_</code><span class="emphasis"><em>i</em></span><code class="literal">.log</code> where <span class="emphasis"><em>i</em></span> ranges from 1 to 4, and logging continues in
a new <code class="literal">log.log</code> file.
</p><p>
Entries in trace files are by default of the form &lt;timestamp&gt; &lt;thread-name&gt; &lt;source&gt; &lt;level&gt; &lt;entry-text&gt;. For example:
</p><pre class="screen">
[2008-05-15 09:09:46.940] server-dm-2 org.apache.coyote.http11.Http11Protocol I Initializing Coyote HTTP/1.1 on http-48080
</pre><p>
although this format is completely determined by the Logback configuration file <code class="literal">serviceability.xml</code>.
</p><div class="section" title="Application Output"><div class="titlepage"><div><div><h3 class="title"><a name="serviceability-info-trace-app"></a>Application Output</h3></div></div></div><p>
Virgo provides advanced support for capturing and tracing application-generated output by automatically separating trace output on a
per-application basis and will also capture any <code class="literal">System.out</code> and <code class="literal">System.err</code> output.
</p><div class="section" title="Per-application trace"><div class="titlepage"><div><div><h4 class="title"><a name="per-application-trace"></a>Per-application trace</h4></div></div></div><p>
Virgo uses SLF4J interfaces to Logback, and the root logger (by default) captures all logging output
and appends it to the application-specific trace files as described above.
To modify this, define application-specific loggers in the <code class="literal">serviceability.xml</code> file in the normal way.
</p></div><div class="section" title="System.out and System.err"><div class="titlepage"><div><div><h4 class="title"><a name="sysout-and-syserr"></a>System.out and System.err</h4></div></div></div><p>
<code class="literal">System.out</code> and <code class="literal">System.err</code> output from applications is, by default, captured in the
application&rsquo;s trace file.
This happens because the output streams are intercepted and written to the loggers named
<code class="literal">System.out</code> and <code class="literal">System.err</code> respectively.
Since there are no explicit loggers defined with these names in the <code class="literal">serviceability.xml</code> file,
this output is logged by the root logger (which captures <code class="literal">INFO</code> level and above).
</p><p>
The capture of <code class="literal">System.out</code> and <code class="literal">System.err</code> output is configured in the
<code class="literal">configuration/org.eclipse.virgo.medic.properties</code> file by the <code class="literal">log.wrapSysOut</code> and
<code class="literal">log.wrapSysErr</code> properties. By default the properties have a value of <code class="literal">true</code>
and capture is enabled. Capture can be disabled by configuring the properties with a value of <code class="literal">false</code>.
</p><p>
The trace entries for <code class="literal">System.out</code> and <code class="literal">System.err</code>
output are of the form:
</p><pre class="screen">
[2008-05-16 09:28:45.874] server-tomcat-thread-1 System.out Hello world!
[2008-05-16 09:28:45.874] server-tomcat-thread-1 System.err Hello world!
</pre><p>
The third column indicates where the output came from (<code class="literal">System.out</code> or <code class="literal">System.err</code>).
</p><p>
To over-ride this behaviour, simply define explicit loggers named <code class="literal">System.out</code>
and/or <code class="literal">System.err</code> in the configuration file to send this output to an appender of your choice.
Be aware that all applications&rsquo; output streams will be caught by these loggers, and that a sifting appender might be useful to separate them.
</p></div><div class="section" title="Janino"><div class="titlepage"><div><div><h4 class="title"><a name="janino"></a>Janino</h4></div></div></div><p>
Janino can be used to define trace filters as Java expressions. This adds a significant overhead to tracing, so should be used with care.
</p><p>
For example, the addition of the following filter element to the sifting appender in <code class="literal">serviceability.xml</code>
suppresses per-application trace output that is not associated with a particular application and is normally written to
<code class="literal">serviceability/logs/virgo-kernel/log.log</code>.
</p><pre class="programlisting">&lt;appender name="SIFTED_LOG_FILE" class="ch.qos.logback.classic.sift.SiftingAppender"&gt;
&lt;discriminator&gt;
&lt;Key&gt;applicationName&lt;/Key&gt;
&lt;DefaultValue&gt;virgo-kernel&lt;/DefaultValue&gt;
&lt;/discriminator&gt;
&lt;sift&gt;
&lt;appender name="${applicationName}_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
&lt;filter class="ch.qos.logback.core.filter.EvaluatorFilter"&gt;
&lt;evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator"&gt;
&lt;expression&gt;
(mdc == null) || (mdc.get("applicationName") == null)
&lt;/expression&gt;
&lt;/evaluator&gt;
&lt;OnMismatch&gt;NEUTRAL&lt;/OnMismatch&gt;
&lt;OnMatch&gt;DENY&lt;/OnMatch&gt;
&lt;/filter&gt;
&lt;file&gt;serviceability/logs/${applicationName}/log.log&lt;/file&gt;
...
&lt;/appender&gt;
&lt;/sift&gt;
&lt;/appender&gt;</pre><p>
</p><p>
To enable Janino in Virgo, place the Janino and commons compiler JARs, converted to OSGi bundles, in <code class="literal">plugins</code>.
For example these bundles are available at v2.6.1 from the SpringSource Enterprise Bundle Repository.
Then add the following lines to
<code class="literal">configuration/org.eclipse.equinox.simpleconfigurator/bundles.info</code>
(as described in <a class="link" href="ch13.html#configuring-framework-bundles" title="Configuring OSGi Framework Bundles">Configuring OSGi Framework Bundles</a>):
</p><pre class="programlisting">com.springsource.org.codehaus.janino,2.6.1,plugins/com.springsource.org.codehaus.janino-2.6.1.jar,4,false
com.springsource.org.codehaus.commons.compiler,2.6.1,plugins/com.springsource.org.codehaus.commons.compiler-2.6.1.jar,4,false</pre><p>
</p><div class="important" title="Important" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Important</h3>
Current versions of Logback, including 0.9.28 to 1.0, do not set Janino's "parent" class loader correctly.
This bug is covered by the Logback issue <a class="ulink" href="http://jira.qos.ch/browse/LBCORE-244" target="_top">LBCORE-244</a>.
With such versions, it is necessary to attach a fragment bundle to Janino. Place the fragment bundle in <code class="literal">plugins</code> and list it in
<code class="literal">configuration/org.eclipse.equinox.simpleconfigurator/bundles.info</code>.
The fragment's contents are described in <a class="ulink" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=333920#c15" target="_top">bug 333920</a>.
</div></div></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="ch11.html">Prev</a>&nbsp;</td><td align="center" width="20%"><a accesskey="u" href="ch11.html">Up</a></td><td align="right" width="40%">&nbsp;<a accesskey="n" href="ch11s03.html">Next</a></td></tr><tr><td valign="top" align="left" width="40%">&nbsp;</td><td align="center" width="20%"><a accesskey="h" href="index.html">Home</a></td><td valign="top" align="right" width="40%">&nbsp;</td></tr></table></div></body></html>