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);