I am running the application in Eclipse. Perhaps it adds the test classpath, even though I am not running a test application. Does a programmatic configuration override log4j2-test configuration or any other file configuration? Because using my own ConfigurationFactory works and it doens't use the file configuration, in either src/main/resources or src/test/resources.
2017-11-24 19:04 GMT+01:00 Matt Sicker <boa...@gmail.com>: > 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....@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 <boa...@gmail.com> >