geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Geronimo v2.2 > Configuring application specific logging with Log4j
Date Wed, 01 Sep 2010 01:47:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=GMOxDOC22&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/GMOxDOC22/Configuring+application+specific+logging+with+Log4j">Configuring
application specific logging with Log4j</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~chirunhua@gmail.com">Runhua
Chi</a>
    </h4>
        <br/>
                         <h4>Changes (3)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-unchanged" >(Available in Geronimo 2.1.1 and later)
<br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Geronimo uses log4j for logging
and the base log4j configuration is in <span class="diff-changed-words"><span class="diff-added-chars"style="background-color:
#dfd;">{{</span>var/log/server-log4j.properties<span class="diff-added-chars"style="background-color:
#dfd;">}}</span>.</span>  If your application also uses log4j for logging you
can configure logging in this file.  However, this is not self-contained.  Instead, you can
configure log4j settings specific to your application in your application plugin. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >Note that in any case, unless
you use <span class="diff-changed-words"><span class="diff-added-chars"style="background-color:
#dfd;">&lt;</span>hidden-classes<span class="diff-added-chars"style="background-color:
#dfd;">&gt;</span></span> or <span class="diff-changed-words"><span
class="diff-added-chars"style="background-color: #dfd;">&lt;</span>inverse-classloading<span
class="diff-added-chars"style="background-color: #dfd;">&gt;</span></span>
to load your own copy of log4j separate from the geronimo copy, log4j will not automatically
read any log4j.properties files you may have included in your classpath. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
If you want to use different configuration file for server logging <br>The configuration
file {{server-log4j.properties}} is hard-coded in {{config.ser}} and cannot be updated via
{{config.xml}}. However, you can swap the default {{server-log4j.properties}} file by overriding
 system property {{org.apache.geronimo.log4jservice.configuration}} as followed: <br>{panel:borderstyle=none}
<br>export GERONIMO_OPTS=-Dorg.apache.geronimo.log4jservice.configuration=$GERONIMO_HOME/var/log/server-log4j.xml
<br>{panel} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. If you are building your own application:
<br>This example is taken from the apache directory plugin for geronimo, so the paths
etc are adapted for that plugin. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>(Available in Geronimo 2.1.1 and later)</p>

<p>Geronimo uses log4j for logging and the base log4j configuration is in <tt>var/log/server-log4j.properties</tt>.
 If your application also uses log4j for logging you can configure logging in this file. 
However, this is not self-contained.  Instead, you can configure log4j settings specific to
your application in your application plugin.</p>

<p>Note that in any case, unless you use &lt;hidden-classes&gt; or &lt;inverse-classloading&gt;
to load your own copy of log4j separate from the geronimo copy, log4j will not automatically
read any log4j.properties files you may have included in your classpath.</p>

<h3><a name="ConfiguringapplicationspecificloggingwithLog4j-Ifyouwanttousedifferentconfigurationfileforserverlogging"></a>If
you want to use different configuration file for server logging</h3>
<p>The configuration file <tt>server-log4j.properties</tt> is hard-coded
in <tt>config.ser</tt> and cannot be updated via <tt>config.xml</tt>.
However, you can swap the default <tt>server-log4j.properties</tt> file by overriding
 system property <tt>org.apache.geronimo.log4jservice.configuration</tt> as followed:</p>
<div class="panel" style="border-width: 1px;"><div class="panelContent">
<p>export GERONIMO_OPTS=-Dorg.apache.geronimo.log4jservice.configuration=$GERONIMO_HOME/var/log/server-log4j.xml</p>
</div></div>

<h3><a name="ConfiguringapplicationspecificloggingwithLog4j-Ifyouarebuildingyourownapplication%3A"></a>If
you are building your own application:</h3>
<p>This example is taken from the apache directory plugin for geronimo, so the paths
etc are adapted for that plugin.</p>

<ol>
	<li>Include an ApplicationLog4jConfigurationGBean in your application plan, like this:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    &lt;gbean name=<span class="code-quote">"DirectoryLog4jConfiguration"</span>
class=<span class="code-quote">"org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"</span>&gt;
        &lt;attribute name=<span class="code-quote">"log4jFile"</span>&gt;<span
class="code-keyword">var</span>/directory/log4j.properties&lt;/attribute&gt;
        &lt;reference name=<span class="code-quote">"ServerInfo"</span>&gt;&lt;name&gt;ServerInfo&lt;/name&gt;&lt;/reference&gt;
    &lt;/gbean&gt;
</pre>
</div></div>
<p>You can also use a log4j.properties file in your classpath, for example, in <tt>WEB-INF/classes/META-INF</tt>.
(If you prefer not to place this file under <tt>WEB-INF/classes/</tt>, the path
of this file must be added to your classpath).  But this will obstruct anyone trying to configure
logging as the file will remain packed in your application somewhere hard to find. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    &lt;gbean name=<span class="code-quote">"DirectoryLog4jConfiguration"</span>
class=<span class="code-quote">"org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"</span>&gt;
        &lt;attribute name=<span class="code-quote">"log4jResource"</span>&gt;META-INF/log4j.properties&lt;/attribute&gt;
    &lt;/gbean&gt;
</pre>
</div></div></li>
	<li>Configure application specific logging in your log4j.properties file.  The gbean
prevents you from overriding settings that apply to global logging, but you can configure
appenders for specific loggers for your application.  Here's the example for ApacheDS:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
#attach an appender to the base apacheds <span class="code-keyword">package</span>
logger:
log4j.logger.org.apache.directory=INFO,apacheds
#<span class="code-keyword">do</span> not log apacheds to geronimo logs:
log4j.additivity.org.apache.directory=<span class="code-keyword">false</span>

#Configure the apacheds specific appender:
log4j.appender.apacheds=org.apache.log4j.DailyRollingFileAppender
log4j.appender.apacheds.File=${org.apache.geronimo.server.dir}/<span class="code-keyword">var</span>/log/apacheds.log
log4j.appender.apacheds.layout=org.apache.log4j.PatternLayout
# geronimo style logging
log4j.appender.apacheds.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n

# some settings <span class="code-keyword">for</span> the apacheds loggers, taken
from the standard apacheds log4j.properties file.
# with these we'll not get innundated when switching to DEBUG
log4j.logger.org.apache.directory.shared.ldap.name=WARN
#log4j.logger.org.springframework=WARN
log4j.logger.org.apache.directory.shared.codec=WARN
log4j.logger.org.apache.directory.shared.asn1=WARN
</pre>
</div></div></li>
</ol>


<h3><a name="ConfiguringapplicationspecificloggingwithLog4j-Ifyouarebuildingapluginusingmavenandthecarmavenplugin%3A"></a>If
you are building a plugin using maven and the car-maven-plugin:</h3>
<ol>
	<li>Include the log4j.properties configuration file in an appropriate location in your
plugin, say META-INF/log4j.properties</li>
	<li>Unpack the log4j.properties file during plugin installation by including something
like this in the pom.xml that generates geronimo-plugin.xml:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.geronimo.buildsupport&lt;/groupId&gt;
                &lt;artifactId&gt;car-maven-plugin&lt;/artifactId&gt;
...
                    &lt;instance&gt;
                        &lt;plugin-artifact&gt;
                            &lt;copy-file relative-to=<span class="code-quote">"server"</span>
dest-dir=<span class="code-quote">"<span class="code-keyword">var</span>/directory"</span>&gt;META-INF/log4j.properties&lt;/copy-file&gt;
...
                        &lt;/plugin-artifact&gt;
                    &lt;/instance&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
</pre>
</div></div></li>
</ol>


<h3><a name="ConfiguringapplicationspecificloggingwithLog4j-Ifyouaredeployingyourappbysomeothermeans%3A"></a>If
you are deploying your app by some other means:</h3>
<p>Copy the log4j.properties file by hand to the appropriate location such as var/my-app/log4j.properties.
 There is no need to include this file in your app.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/GMOxDOC22/Configuring+application+specific+logging+with+Log4j">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=93404&revisedVersion=11&originalVersion=10">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/GMOxDOC22/Configuring+application+specific+logging+with+Log4j?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message