'log4j - log4j-core update
I have updated my log4j version from 1.2.17 to log4j-core-2.17.1, this is for the log4jshell vulnerability fix.
While building the code, I am getting the cannot find PatternLayout and ConsoleAppender error message.
I should not have other any log4j version other than log4j-core-2.17.1 in the war file, so I have excluded lo4j in the slf4j dependency in pom.xml file
Please know how to fix this error.
Code Snippet
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ConsoleAppender;
import org.apache.logging.log4j.PatternLayout;
import jxl.common.Logger;
public class Booking {
static Logger logger = Logger.getLogger(Booking.class);
public static boolean isChecked(String[] includeProps) {
logger.info("Start of method");
return true;
}
}
pom.xml
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.36</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
log4j.properties
log4j.rootLogger=INFO,stdout
log4j.logger.requestLogger=debug, requestAppender
log4j.additivity.requestLogger=false
log4j.appender.stdout=org.apache.log4j.FileAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.File=/apps/opt/logs/App.log
log4j.appender.stdout.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n
Error message
cannot find symbol
[ERROR] symbol: class PatternLayout
cannot find symbol
[ERROR] symbol: class ConsoleAppender
[ERROR] symbol: class variable Logger
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
