Lately I decided to learn how to use the log4j2 logger. I downloaded required jar files, created library, xml comfiguration file and tried to use it. Unfortunately i get this statement in console (Eclipse) :
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
This is my testing class code:
package log4j.test; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class Log4jTest { static final Logger logger = LogManager.getLogger(Logger.class.getName()); public static void main(String[] args) { logger.trace("trace"); logger.debug("debug"); logger.info("info"); logger.warn("warn"); logger.error("error"); logger.fatal("fatal"); } }
And my xml config file:
<?xml version="1.0" encoding="UTF-8"?> <Configuration package="log4j.test" status="WARN"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console> </Appenders> <Loggers> <Logger name="log4j.test.Log4jTest" level="trace"> <AppenderRef ref="Console"/> </Logger> <Root level="trace"> <AppenderRef ref="Console"/> </Root> </Loggers> </Configuration>
I tried also with xml without <Logger>
tags, and package specification and in various folders/packages directories, but it didn't help. Now my log4j2.xml
file is located directly in project folder in eclipse.
Well, a solution is simplexml version="1.0" encoding="UTF-8"?> Try running your program again and you shouldn't see this issue anymore. Hope this helps.
Configuration of Log4j 2 can be accomplished in 1 of 4 ways: Through a configuration file written in XML, JSON, YAML, or properties format. Programmatically, by creating a ConfigurationFactory and Configuration implementation.
The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file.
We should put log4j2. xml anywhere in the application's classpath. Log4j will scan all classpath locations to find out this file and then load it. We can find this file mostly placed in the 'src/main/resources' folder.
Is this a simple eclipse java project without maven etc? In that case you will need to put the log4j2.xml
file under src
folder in order to be able to find it on the classpath. If you use maven put it under src/main/resources
or src/test/resources
You need to choose one of the following solutions:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With