I am not using any XML configuration file, rather I am setting the logger configuration programmatically. The logger works correctly but just when I call the first line of the code below, a warning ERROR
message shows up to tell me that the configuration file was not found and default configuration will be used.
But I don't want this message to be displayed on the console every time I rung the program because I will programmatically add the configuration myself.
The message:
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
It comes when I call the code below:
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Or if I get the root logger first:
Logger logger = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
Is there some kind of property that I can set to disable this message from being displayed? Or another approach?.
NOTE: I disabled another notification regarding Log4j2 JMX by setting the property -Dlog4j2.disable.jmx=true
. But I couldn't find for this one.
Add the following system property in order to not show that message:
-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=OFF
Alternatively, and more simply:
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.status.StatusLogger;
...
StatusLogger.getLogger().setLevel(Level.OFF);
You can simply do this in your main class.
static {
StatusLogger.getLogger().setLevel(Level.OFF);
}
You have to implement initialize method for proper initialization of log4j configurations from code.
Check the "How do I configure log4j2 in code without a configuration file" section in below page which provides the source code also.
http://logging.apache.org/log4j/2.x/faq.html
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