users@glassfish.java.net

Re: Glassfish + log4j + multiple log4j.xml

From: Markus Weiß <weiss.mark_at_gmx.de>
Date: Thu, 14 Jan 2010 16:35:43 +0100

Hi,

if you want to have own log-files per application (or let's say one
configuration file per application) you have to place log4j (and if you
use it commons-logging) in the application libs (e.g. WEB-INF/lib)
itself and not in the domain lib because each log4j instance loads only
one configuration file. See discussion on theserverside:

http://www.theserverside.com/discussions/thread.tss?thread_id=27334#224381

I don't know freemarker, but I hope this helps!

glassfish_at_javadesktop.org wrote:
> Hi all!
> Situation:
> Application Server: Glassfish v.2.1
> OS: Windows XP
> Number of application in domain: 3 independent applications
> Each application contains ejb and web module.
>
> Task: to organize logging policy:each application has its own log-file.
>
> Internet "tells" me a solution (on server side):
> 1) place log4j.jar into .../domains/domain1/lib
> 2) for each application create its own log4j.xml (configuration file) and place it in WEB-INF/classes folder
> 3) restart the server
>
> How I did it:
>
> 1) clear
> 2) xml for first application (named 'fsvps')
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
> <log4j:configuration>
> <appender name="fileLogger" class="org.apache.log4j.RollingFileAppender">
> <param name="File" value="../logs/fsvps.log" />
> <param name="encoding" value="UTF-8" />
> <param name="MaxFileSize" value="2000KB"/>
> <param name="MaxBackupIndex" value="10"/>
> <param name="Append" value="true" />
> <layout class="org.apache.log4j.PatternLayout">
> <param name="ConversionPattern" value="%p %t %c - %m%n"/>
> </layout>
> </appender>
> <logger name="fsvps" additivity="false">
> <level value="trace"/>
> <appender-ref ref="fileLogger"/>
> </logger>
> <root>
> <level value ="trace"/>
> <appender-ref ref="fileLogger"/>
> </root>
> </log4j:configuration>
>
> for other applications xml is the same but I changed fsvps.log to fsvps-rpt.log and fsvps-losts.log accordingly and I changed name of logger to fsvps-rpt and fsvps-losts accordingly.
>
> Note:First application uses freemarker
> Other 2 (fsvps-rpt, fsvps-losts) dont't use freemarker
>
> 3) When I restart the server and go to the log directory I find the fsvps.log file (as I expect). From Freemarker manual:
>
> "FreeMarker integrates with the following logging packages: Log4J, Avalon LogKit, and java.util.logging (Java2 platform 1.4 and above). You need not do anything in order for FreeMarker to use these loggers; if any of them is discovered through the class loader that loaded FreeMarker classes, it is used automatically. All log messages produced by FreeMarker are logged into the logger hierarchy whose top-level logger is named freemarker."
>
> But I can't find other 2 files in the same directory. And in the server.log I find:
>
> [#|2010-01-13T16:06:15.859+0300|INFO|sun-appserver2.1|org.apache.catalina.loader.WebappLoader|_ThreadID=15;_ThreadName=pool-1-thread-2;|Unknown loader Application library chain for fsvps-rpt parentCL :: EJBClassLoader :
> urlSet = []
> doneCalled = false
> Parent -> java.net.URLClassLoader_at_137d4a4
> constituent CLs ::
> :: null :: optionalChain
> class com.sun.appserv.server.util.ClassLoaderChain|#]
>
> Next. If I undeploy fsvps and restart server I find again 1 file - fsvps-losts.log or fsvps-rpt.log, depending on what application I addressed to first.
>
> How can I resolve my problem and achieve the main goal? I've been skirmishing for solution more than 2 days (
> [Message sent by forum member 'arttaras' (arttaras_at_mail.ru)]
>
> http://forums.java.net/jive/thread.jspa?messageID=380625
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>