Remo
Remo

Reputation: 1412

Log4J Properties not found / no effect

I've got a Web application with Tomcat and would like to add Log4J2. Logging to the console by default works just fine. Although, I've added a log4j2.properties to add a File appender to my project and write the log to a dedicated location. Unfortunately, it seems that my properties-File has no effect.

Path to properties-File: /WEB-INF/log4j2.properties

enter image description here

Configs of log4j2.properties

name=Log4j2PropertiesConfig
appenders=file
appender.file.type=File
appender.file.name=FileLogger
appender.file.filename=logs/app.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=%d [%t] %-5p %c - %m%n
rootLogger.level=all
rootLogger.appenderRefs=file
rootLogger.appenderRef.file.ref=FileLogger

How I create the logger inside a class:

private val logger: Logger = LoggerFactory.getLogger(this.javaClass)

What am I doing wrong?

Upvotes: 0

Views: 432

Answers (2)

Remo
Remo

Reputation: 1412

https://www.codejava.net/coding/how-to-initialize-log4j-for-java-web-application

The tutorial solves my problem as it defines a way on how to keep the properties in the WEB-INF.

Upvotes: 0

Dmitrii B
Dmitrii B

Reputation: 2860

try to put the file log4j2.properties into src/main/resources. It should allocate in classpath

Upvotes: 2

Related Questions