logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Sicker <boa...@gmail.com>
Subject Re: Main application uses log4j2-test.xml in Eclipse
Date Fri, 24 Nov 2017 18:04:03 GMT
Are you running your application using your main classpath or your test
classpath? It's a feature of log4j2 to use the test config first based on
typical classpath usage scenarios. If there's no way for you to run your
application without the test classpath, then you can set the config file
system property (log4j.configurationFile) to manually specify the path to
the file.

On 23 November 2017 at 02:08, Sverre Moe <sverre.moe@gmail.com> wrote:

> Running my main application in Eclipse it is using the log4j2-test.xml
> configuration, and not the log4j2.xml configuration.
>
> src/main/resources/log4j2.xml
> src/test/resources/log4j2-test.xml
>
> I am not running a test application under src/test, but my main application
> under src/main/
> target/classes/log4j2.xml
> target/test-classes/log4j2-test.xml
>
> How do I avoid it using the log4j2-test.xml when running from Eclipse?
>
> With a programmatic configuration it does not pick the log4j2-text.xml.
>
> *My XML configuration:*
> <?xml version="1.0" encoding="UTF-8"?>
>
> <!-- Don't forget to set system property
> -DLog4jContextSelector=org.apache.logging.log4j.core.async.
> AsyncLoggerContextSelector
>     to make all loggers asynchronous. -->
>
> <Configuration status="WARN">
>     <Properties>
>         <Property name="pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS}
> [%level] %logger: %m%n" />
>     </Properties>
>     <Appenders>
>         <!-- Async Loggers will auto-flush in batches, so switch off
> immediateFlush. -->
>         <RollingRandomAccessFile name="RollingRandomAccessFile"
> fileName="${sys:user.home}/.app/app.log"
>             filePattern="app-%d{yyyy-MM-dd}-%i.log.gz"
> immediateFlush="false" append="false">
>             <PatternLayout>
>                 <Pattern>${pattern}</Pattern>
>             </PatternLayout>
>             <Policies>
>                 <OnStartupTriggeringPolicy />
>             </Policies>
>         </RollingRandomAccessFile>
>     </Appenders>
>     <Loggers>
>         <Logger name="com.company" level="ERROR" includeLocation="false"
> additivity="false">
>             <AppenderRef ref="RollingRandomAccessFile" />
>         </Logger>
>         <Root level="WARN" includeLocation="false">
>             <AppenderRef ref="RollingRandomAccessFile" />
>         </Root>
>     </Loggers>
> </Configuration>
>
>
> /Sverre
>



-- 
Matt Sicker <boards@gmail.com>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message