Here is the error message -
log4j:WARN No appenders could be found for logger (SerialPortUtil).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Here is the invocation in the SerialPortUtil
class -
private static final Logger log = Logger.getLogger(SerialPortUtil.class.getSimpleName());
.
.
.
log.info("Serial port " + port.getName() + " is available");
Here is the content of my log4j.properties file -
log4j.rootLogger=DebugAppender
#Debug logging
log4j.appender.DebugAppender=org.apache.log4j.RollingFileAppender
log4j.appender.DebugAppender.Threshold=DEBUG
log4j.appender.DebugAppender.File=activityLog.log
log4j.appender.DebugAppender.MaxFileSize=200KB
log4j.appender.DebugAppender.MaxBackupIndex=5
log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.DebugAppender.layout.ConversionPattern=%d{DATE} %t - %m%n
And the property file is on the classpath.
Everything looks right to me, so what's going on? Shouldn't the DEBUG
threshold also capture INFO
logging?
This work for me:
just configure your log4j property file path in beginning of main method: e.g.: PropertyConfigurator.configure("D:\files\log4j.properties");
What worked for me is to create a log4j properties file (you can find many examples over the net) and place it in properties folder in your project directory (create this folder if not exicts). The right click on the folder and
Build Path->Use as Source Folder
.Hope it helps!
The fix for me was to put "log4j.properties" into the "src" folder. It did not work in my package folder it has to be one up at the very root of source. Adding it to the build path which then moves it to the "Reference Libraries" also did not work.
To repeat: put log4j.properties at the root of your src folder.
my log4j.properties files has the following content which works on the latest version of Spring Tool Suite which is based on Eclipse.
From the link in the error message:
The configuration file cannot be found. Are you using xml or a property file??
Also, use logback!
Try doing something like the following in main:
you need to tell log4j what its configuration should be.