After adding log4j to my application I get the following output every time I execute my application:
log4j:WARN No appenders could be found for logger (slideselector.facedata.FaceDataParser). log4j:WARN Please initialize the log4j system properly.
It seems this means a configuration file is missing. Where should this config file be located and what is a good start content?
I'm using plain java for developing a desktop application. So no webserver etc...
As explained earlier there are 2 approaches
First one is to just add this line to your main method:
Second approach is to add this standard log4j.properties file to your classpath:
While taking second approach you need to make sure you initialize the file properly.
Eg.
Make sure you create required folder to store log files.
My log4j got fixed by below property file:
Find a log4j.properties or log4j.xml online that has a root appender, and put it on your classpath.
will log to the console. I prefer logging to a file so you can investigate afterwards.
although for verbose logging applications 100KB usually needs to be increased to 1MB or 10MB, especially for debug.
Personally I set up multiple loggers, and set the root logger to warn or error level instead of debug.
This is an alternative way using .yaml
Logic Structure:
Sample:
Ref: LOG4J 2 CONFIGURATION: USING YAML
Another way to do it without putting the property file on the classpath, is to set the property from the java code directly. Here is the sample code.
}
Simply, create log4j.properties under src/main/assembly folder. Depending on if you want log messages to be shown in the console or in the file you modify your file. The following is going to show your messages in the console.