[ 
https://issues.apache.org/jira/browse/LOG4J2-484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13866506#comment-13866506
 ] 

Remko Popma commented on LOG4J2-484:
------------------------------------

Different web applications can have separate log4j2.xml configurations (because 
they have different classloaders), but within the same web application it is 
not possible to have two different log4j2.xml configurations.

However, it is possible to direct the logging done by 
{{HelloWorldServletContextListener}} to a separate log file. You don't need a 
separate configuration to do this. Details for this are in the [configuration 
manual|http://logging.apache.org/log4j/2.0/manual/configuration.html], 
especially the 
[additivity|http://logging.apache.org/log4j/2.0/manual/configuration.html#Additivity]
 section.

Something like this should result in a separate log file for 
{{HelloWorldServletContextListener}}, with all other logging going to the 
default log file:
{code}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <RollingFile name="TheDefaultLogFile" 
fileName="/tmp/default_MavenWeb.log" 
                          
filePattern="/tmp/default_MavenWeb.log.%d{yyyy-MM-dd}" append="true">
        <PatternLayout>
          <Pattern>%d %-5p [%t] %c %l -- %m%n</Pattern>
        </PatternLayout>
        <Policies>
          <TimeBasedTriggeringPolicy modulate="true"/> <!-- rotated everyday -->
        </Policies>
      </RollingFile>
      <RollingFile name="ContextListenerOnlyLogFile" 
fileName="/tmp/MavenWeb.log" 
                        filePattern="/tmp/MavenWeb.log.%d{yyyy-MM-dd}" 
append="true">
        <PatternLayout>
          <Pattern>%d %-5p [%t] %c %l -- %m%n</Pattern>
        </PatternLayout>
        <Policies>
          <TimeBasedTriggeringPolicy modulate="true"/> <!-- rotated everyday -->
        </Policies>
      </RollingFile>
    </Appenders>
    <Loggers>
      <!-- additivity is false so the HelloWorldServletContextListener log 
messages 
           don't also appear in the default log file -->
      <Logger name="net.viralpatel.maven.HelloWorldServletContextListener" 
level="trace" additivity="false">
        <AppenderRef ref="ContextListenerOnlyLogFile"/>
      </Logger>
      <Root level="debug">
        <AppenderRef ref="TheDefaultLogFile"/>
      </Root>
    </Loggers>
</Configuration>
{code}

> log4j2 and ServletContextListeners
> ----------------------------------
>
>                 Key: LOG4J2-484
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-484
>             Project: Log4j 2
>          Issue Type: Question
>          Components: Configurators
>    Affects Versions: 2.0-beta9
>         Environment: java 1.7.0_11-b21, tomcat-7.0.14
>            Reporter: Giovanni Mondo
>            Priority: Trivial
>              Labels: newbie
>             Fix For: 2.0-rc1
>
>         Attachments: MavenWeb2.zip
>
>
> Logging configuration is done by two config file:
> WEB-INF/classes/log4j2.xml  logging in /tmp/default_MavenWeb.log
> and
>  
> /tmp/final_log4j2.xml as log4jConfiguration of a Log4jServletContextListener 
> logging in /tmp/MavenWeb.log
>  
> Is it possible to log HelloWorldServletContextListener in /tmp/MavenWeb.log 
> as HelloWorldServlet does ? 
> A minimal maven project with full details can be found in attachment.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to