简体   繁体   中英

How to stop printing log4j FileNotFound Error on console?

I created a utility for moving some text data into a SQL database and have implemented logging(log4j) for debugging purposes. Once i created a jar of my utility and called it for execution, the utility works fine but each time, the output is preceded by the below error message:

log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (The system cannot find the file specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:306)
        at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:324)
        at spotfire.loadtest.Driver.main(Driver.java:28)
log4j:ERROR Ignoring configuration file [log4j.properties].
log4j:WARN No appenders could be found for logger (spotfire.loadtest.Driver).
log4j:WARN Please initialize the log4j system properly.

Please note that my utility works and the text is inserted into the database. The only issue I face is how to get rid of this error message. Is there any way to stop printing it altogether??

Either your log4j.properties has to be in classpath or you need to specify it as JVM Argument as

-Dlog4j.configuration={path to file}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM