I'm trying to change from log4j1 to log4j2. What I did:
- deleted old configuration file log4j.xml
- created new config file log4j2.xml
- created jboss-deployment-structure.xml
- edited pom
Environment: Wildfly 10 1 EAR 4 WAR The web.xml isn't being used in the file. The previous log4j config log was in the EAR (only)
Log4j2 config file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<File name="MyFile" fileName="all.log" immediateFlush="false" append="false">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
<AppenderRef ref="MyFile"/>
</Root>
</Loggers>
</Configuration>
Jboss deployment structure
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<!--Use log4j.xml file instaead of using the loggin subsystem configuration -->
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
new maven dependencies
<!-- Apache Log4j API -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>
<!-- Apache Log4j SLF4J Binding -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8.2</version>
</dependency>
<!-- Apache Log4j Core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
Has I said earlier I was using log4j1 with SLF4j has facade. These are the changes I've made (I'm trying to start with a simple configuration file I've found online). The file is not even created, but the console log is working just fine.
Thanks,
all.log
to an absolute path where everyone has permissions like/Users/yourname/Desktop/all.log
on Mac orC:\users\yourname\Desktop\all.log
on Windows. I'm not 100% on the windows path being correct, but you can double check. – tima