Best way to use file appender of log4j in spring without absolute path
Well, i think most of developer faced the same problem as i did this afternoon: the spring cannot find file path based on the log4j.properties file. Unless, you gave log4j a absolute path for file appender.
That is totally bad. Because no one will know your web service will be deployed on which environment.
So this is the answer: Use Log4jConfigListener. It allows you to store your log file in /WEB-INF/logs/ without absolute path by using as following:
log4j.appender.logfile.File=${webapp.root}/WEB-INF/logs/myfuse.log Juse make sure you put the Log4jConfigListener before the spring listener.
Add those to your web.xml: