Sure.  Here's the basic structure

imports...
public class CommonClass
{
class/instance data declarations...
static {
DOMConfigurator.configureAndWatch(logInitFile);
}
methods...
}

where logInitFile is an xml file that only declares the root category
and appenders.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>
  <appender name="R"
class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="${acsauth.loghome}/CommonClass.log"/>
    <param name="Append" value="true"/>
    <param name="DatePattern" value="'.'yyyy-MM-dd'.log'"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern"
value="[slf5s.start]%d{DATE}[slf5s.DATE]%n%p[slf5s.PRIORITY]%n%x[slf5s.NDC]%n%t[slf5s.THREAD]%n%c[slf5s.CATEGORY]%n%l[slf5s.LOCATION]%n%m[slf5s.MESSAGE]%n%n"/>
    </layout>
  </appender>

  <root>
    <priority value ="info"/>
    <appender-ref ref="R"/>
  </root>

Then you do the init servlet (let me know if you need an example of
this) that loads a different xml config file that only declares a
category/appenders for that app:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>
<appender name="alisonLogFile"
class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="${acsauth.loghome}/alison.log"/>
    <param name="Threshold" value="INFO"/>
    <param name="Append" value="true"/>
    <param name="DatePattern" value="'.'yyyy-MM-dd'.log'"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern"
value="[slf5s.start]%d{DATE}[slf5s.DATE]%n%p[slf5s.PRIORITY]%n%x[slf5s.NDC]%n%t[slf5s.THREAD]%n%c[slf5s.CATEGORY]%n%l[slf5s.LOCATION]%n%m[slf5s.MESSAGE]%n%n"/>
    </layout>
  </appender>
  
  <category name="alison" additivity="false">
    <level value="info"/>
    <appender-ref ref="alisonLogFile"/>
  </category>

I think I remember getting a warning about not having a root appender
during the init servlet, but it seemed to run ok and behave as I would
expect.  If you change the additivity param to true, the events will get
logged to both the root and app category appenders.

Hope that helps - let me know if you need more info.

Alison Ortega
North Carolina State University
ACS 
Systems Programmer II
919-513-1417

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to