configuring individually loggingf for every war application in an ear project
My ear project consists of two war applications. i want to create logs individually for every war. i mean every war projects must create its own logs. But, because of they run in the same jvm, i am not sure whether it is possible or not. how can i handle this issue? By the way, the war applications are spring projects. i created two log4j config files (log4j_app1.xml and log4j_app2.xml) and instantiated them in the applicationcontexts but it did not solve the problem. WAR_APP1 applcaitoncontext.xml : bean id=log4jInitialization class=org.springframework.beans.factory.config.MethodInvokingFactoryBean property name=targetClass value=org.springframework.util.Log4jConfigurer / property name=targetMethod value=initLogging / property name=arguments list value/config/log4j_app1.xml/value /list /property /bean WAR_APP2 applcaitoncontext.xml : bean id=log4jInitialization class=org.springframework.beans.factory.config.MethodInvokingFactoryBean property name=targetClass value=org.springframework.util.Log4jConfigurer / property name=targetMethod value=initLogging / property name=arguments list value/config/log4j_app2.xml/value /list /property /bean log4j_app1.xml ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=appender class=org.apache.log4j.DailyRollingFileAppender param name=DatePattern value='.'-MM-dd/ param name=File value=/logs/app1/app1.log/ param name=Append value=true/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d [%t] %p - %m%n/ /layout /appender appender name=console class=org.apache.log4j.ConsoleAppender param name=Target value=System.out/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d - %5p %c{1} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=appender/ appender-ref ref=console/ /root /log4j:configuration log4j_app2.xml ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=appender_ui class=org.apache.log4j.DailyRollingFileAppender param name=DatePattern value='.'-MM-dd/ param name=File value=/logs/app2/app2.log/ param name=Append value=true/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d [%t] %p - %m%n/ /layout /appender appender name=console_ui class=org.apache.log4j.ConsoleAppender param name=Target value=System.out/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d - %5p %c{1} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=appender_ui/ appender-ref ref=console_ui/ /root /log4j:configuration
Re: configuring individually loggingf for every war application in an ear project
If the webapps are configured to use child-first, or parent-last, classloading and log4j.jar is in WEB-INF/lib and log4j.xml is in WEB-INF/classes (or you specify the config path yourself using the Spring configuration utility), then logging should be separated. Shared libraries located outside of WEB-INF/lib (such as in APP-INF/lib under Weblogic) can be problematic since they'll have dependency on Log4j and won't be able to reference it under each webapp's WEB-INF/lib. The other option is a repository selector, but that entails some more complication. There's documentation for it in the logging-log4j wiki [1]. You may still end up with problems when shared libraries log using static loggers, though, since they will be tied to the configuration of the first app that accesses them. [1] http://wiki.apache.org/logging-log4j/AppContainerLogging Jake On Tue, 21 Jun 2011 18:03:20 +0300 Melih U. Ünsal melihun...@gmail.com wrote: My ear project consists of two war applications. i want to create logs individually for every war. i mean every war projects must create its own logs. But, because of they run in the same jvm, i am not sure whether it is possible or not. how can i handle this issue? By the way, the war applications are spring projects. i created two log4j config files (log4j_app1.xml and log4j_app2.xml) and instantiated them in the applicationcontexts but it did not solve the problem. WAR_APP1 applcaitoncontext.xml : bean id=log4jInitialization class=org.springframework.beans.factory.config.MethodInvokingFactoryBean property name=targetClass value=org.springframework.util.Log4jConfigurer / property name=targetMethod value=initLogging / property name=arguments list value/config/log4j_app1.xml/value /list /property /bean WAR_APP2 applcaitoncontext.xml : bean id=log4jInitialization class=org.springframework.beans.factory.config.MethodInvokingFactoryBean property name=targetClass value=org.springframework.util.Log4jConfigurer / property name=targetMethod value=initLogging / property name=arguments list value/config/log4j_app2.xml/value /list /property /bean log4j_app1.xml ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=appender class=org.apache.log4j.DailyRollingFileAppender param name=DatePattern value='.'-MM-dd/ param name=File value=/logs/app1/app1.log/ param name=Append value=true/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d [%t] %p - %m%n/ /layout /appender appender name=console class=org.apache.log4j.ConsoleAppender param name=Target value=System.out/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d - %5p %c{1} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=appender/ appender-ref ref=console/ /root /log4j:configuration log4j_app2.xml ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=appender_ui class=org.apache.log4j.DailyRollingFileAppender param name=DatePattern value='.'-MM-dd/ param name=File value=/logs/app2/app2.log/ param name=Append value=true/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d [%t] %p - %m%n/ /layout /appender appender name=console_ui class=org.apache.log4j.ConsoleAppender param name=Target value=System.out/ layout class=org.apache.log4j.PatternLayout param name=ConversionPattern value=%d - %5p %c{1} - %m%n/ /layout /appender root priority value=info/ appender-ref ref=appender_ui/ appender-ref ref=console_ui/ /root /log4j:configuration - To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org
AW: configuring individually loggingf for every war application in an ear project
Define loggers and appenders for each war! Then if you see that messages get logged twice find who is logging it. Then set the additivity for that logger to false, and that's prevents that logrecords from this identified logger are propagated upward in the logger hierarchy to the next more common logger. Look to loggers as a tree where only the loggeers at the leafe positioon shall log and by using additivity=false for that logger the leave logger will not propagate the message to the trees and more toward the root logger. My apps has many loggers . # --- #- Set your loggers priority to what you need --- # Logger logging WHAT it logs WHO is actually logging log4j.logger.org.apache.catalina=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.coyote=INFO,CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.jasper=INFO,CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.jk=INFO,CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.tomcat=INFO,CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.commons=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.axiom=WARN, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.axis2=INFO, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.org.apache.axis2.deployment=DEBUG, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.de.hunsicker.jalopy.io=FATAL, CONSOLE, R, CHAINSAW_CLIENT log4j.logger.httpclient.wire.header=FATAL, CONSOLE, R, CHAINSAW_CLIENT # --- #- create the SpServer Logger --- # this is the CONFIGURED logger for the SpServer.java JavaPart # the Configurator strips of the logger_prefix log4j.logger. # the logger is then known in the hierarchy as # axawl.spezpla.servers.SpezplaService.SpServer #retrive this configured logger from log4j.hierarchy through # Logger log = Logger.getLogger(SpServer.class); log4j.logger.axawl.spezpla.servers.SpezplaService.SpServer=INFO, LOGFILE, CHAINSAW_AXIS2 # --- # define the additivities used to prevent logging twice the same msg # NOTE: each logger needs an additivity set or you risk logging twice # log4j.additivity.org.apache.axiom=false log4j.additivity.org.apache.axis2=false log4j.additivity.org.apache.axis2.deployment=false log4j.additivity.org.apache.catalina=false log4j.additivity.org.apache.coyote=false log4j.additivity.org.apache.jasper=false log4j.additivity.org.apache.jk=false log4j.additivity.org.apache.commons=false # to prevent that logging events are propagated to parent loggers # and finally arrive at the root loggers appender, printed to the root- # loggers files i.e. additivity must be set to false to prevent this. # please goto http://logging.apache.org/log4j/1.2/manual.html and read # the short manual or buy the full manual log4j.additivity.axawl.spezpla.servers.SpezplaService.SpServer=false Josef -Ursprüngliche Nachricht- Von: Melih U. Ünsal [mailto:melihun...@gmail.com] Gesendet: Dienstag, 21. Juni 2011 17:03 An: log4j-user@logging.apache.org Betreff: configuring individually loggingf for every war application in an ear project My ear project consists of two war applications. i want to create logs individually for every war. i mean every war projects must create its own logs. But, because of they run in the same jvm, i am not sure whether it is possible or not. how can i handle this issue? By the way, the war applications are spring projects. i created two log4j config files (log4j_app1.xml and log4j_app2.xml) and instantiated them in the applicationcontexts but it did not solve the problem. WAR_APP1 applcaitoncontext.xml : bean id=log4jInitialization class=org.springframework.beans.factory.config.MethodInvokingFactoryBean property name=targetClass value=org.springframework.util.Log4jConfigurer / property name=targetMethod value=initLogging / property name=arguments list value/config/log4j_app1.xml/value /list /property /bean WAR_APP2 applcaitoncontext.xml : bean id=log4jInitialization class=org.springframework.beans.factory.config.MethodInvokingFactoryBean property name=targetClass value=org.springframework.util.Log4jConfigurer / property name=targetMethod value=initLogging / property name=arguments list value/config/log4j_app2.xml/value /list /property /bean log4j_app1.xml ?xml version=1.0 encoding=UTF-8? !DOCTYPE log4j:configuration SYSTEM http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/; appender name=appender class=org.apache.log4j.DailyRollingFileAppender param name=DatePattern value='.'-MM-dd/ param name