Upss.. I think I'm a little bit newbie for your answer.
Maybe It could be more useful to me if I show you what, and how I'm doing now, and
from it you give some guidelines on how to complete my work... Could you??
Let's see...
I use properties to configure, not XML.
Here is an extract of the common classes logging properties:
#logger
log4j.logger.clases=info, ApClasesStdOut, ApClasesFile
#appenders
log4j.appender.ApClasesStdOut=org.apache.log4j.ConsoleAppender
log4j.appender.ApClasesStdOut.layout=org.apache.log4j.PatternLayout
log4j.appender.ApClasesStdOut.layout.ConversionPattern=%m%n
log4j.appender.ApClasesFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ApClasesFile.File=${catalina.home}/logs/classes.log
log4j.appender.ApClasesFile.DatePattern='.'yyyy-MM-dd
log4j.appender.ApClasesFile.layout=org.apache.log4j.PatternLayout
log4j.appender.ApClasesFile.layout.ConversionPattern=[%d{dd/MMM/yyyy HH:mm:ss,SSS}] -
%m%n
And here, an extract of the configuration of some app:
#logger
log4j.logger.cl.sichile.delivery = INFO, app_delivery
#app appender
log4j.appender.app_delivery=org.apache.log4j.DailyRollingFileAppender
log4j.appender.app_delivery.File=${catalina.home}/logs/delivery.log
log4j.appender.app_delivery.DatePattern='.'yyyy-MM-dd
log4j.appender.app_delivery.layout=org.apache.log4j.PatternLayout
log4j.appender.app_delivery.layout.ConversionPattern=[%d{dd/MMM/yyyy HH:mm:ss,SSS}] -
Clase: %C - %m%n
Following is the code of the servlet:
imports ...
public class Log4jLauncher extends HttpServlet {
public void init() {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
if(file != null) {
System.out.println("Initializing Log4j with = "+prefix+file);
PropertyConfigurator.configure(prefix+file);
}
}
public void doGet(HttpServletRequest req, HttpServletResponse res) { }
}
And now, the big big question...
How and when I read the configuration of the common classes.
Sorry the misunderstanding, but I can't solve this puzzle!
Again, THANK YOU SO MUCH!!!
Best Regards!
Carlos Yaconi Hitschfeld
-----Mensaje original-----
De: Alison Ortega [mailto:[EMAIL PROTECTED]
Enviado el: Mi�rcoles, 11 de Junio de 2003 12:47
Para: [EMAIL PROTECTED]
Asunto: RE: Problem configuring log4j with common classes
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]