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 Tue, 14 Jul 2009 02:27:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=GMOxDOC22&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://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="http://cwiki.apache.org/confluence/display/~sophia">Ying
Tang</a>
    </h4>
     
          <br/>
     <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 var/log/server-log4j.properties.
 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 hidden-classes or inverse-classloading 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>

<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:
<style type="text/css">
@import url(/confluence/download/resources/confluence.ext.code:code/shStyles.css);
</style>
<!--[if IE]>
<style type="text/css">
    .code textarea, .code input { padding: 0 !important; }
</style>
<![endif]-->
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>
<div class="code">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">&lt;gbean
name="DirectoryLog4jConfiguration" class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"&gt;
        &lt;attribute name="log4jFile"&gt;var/directory/log4j.properties&lt;/attribute&gt;
        &lt;reference name="ServerInfo"&gt;&lt;name&gt;ServerInfo&lt;/name&gt;&lt;/reference&gt;
    &lt;/gbean&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</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">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">&lt;gbean
name="DirectoryLog4jConfiguration" class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean"&gt;
        &lt;attribute name="log4jResource"&gt;META-INF/log4j.properties&lt;/attribute&gt;
    &lt;/gbean&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>
</li>
</ol>


<ol>
	<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">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">#attach
an appender to the base apacheds package logger:
log4j.logger.org.apache.directory=INFO,apacheds
#do not log apacheds to geronimo logs:
log4j.additivity.org.apache.directory=false

#Configure the apacheds specific appender:
log4j.appender.apacheds=org.apache.log4j.DailyRollingFileAppender
log4j.appender.apacheds.File=${org.apache.geronimo.server.dir}/var/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 for 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</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</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">
<textarea name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">&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="server" dest-dir="var/directory"&gt;META-INF/log4j.properties&lt;/copy-file&gt;
...
                        &lt;/plugin-artifact&gt;
                    &lt;/instance&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;</textarea>
<script class="javascript">
    if(!window.newcodemacro_initialised)
    {
        window.newcodemacro_initialised = true;
        window.oldonloadmethod = window.onload;
        window.onload = function(){
            dp.SyntaxHighlighter.HighlightAll('newcodemacro');
            if(window.oldonloadmethod)
            {
                window.oldonloadmethod();
            }
        }
    }

</script>
</div>

<h3><a name="ConfiguringapplicationspecificloggingwithLog4j-Ifyouaredeployingyourappbysomeothermeans%3A"></a>If
you are deploying your app by some other means:</h3></li>
	<li>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.</li>
</ol>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/GMOxDOC22/Configuring+application+specific+logging+with+Log4j">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=93404&revisedVersion=7&originalVersion=6">View
Change</a>
              |
       <a href="http://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