During deployment of a web application (in test environment) on customer site we encountered a problem with logging of the application. I'll shortly try to describe the current situation:
The customer decided that he wants to use Log4J on tomcat and configured it so it works (generally) - of course it's not working for the mentioned application.
As it seems that we need to change logging implementation anyway - i wanted to ask you for some best practices on how to implement logging in a web application. Following things should be possible:
Customer needs to be able to change log-level without modifying anything in the *.war-file.
You can put logging framework configuration file ( log4j.xml
or logback.xml
) outside of the WAR file. Also logback supports automatic reconfiguration when this file is changed.
It should be possible to have some kind of rolling-file-logging
Both log4j and Logback support rolling back of files, both based on size and date, see eg RollingFileAppender
.
As another customer might want to use standard JUL-logging instead - I'd of course prefer to not hard-code the preferred library (Log4J in this case).
apache-commons-logging is fundamentally broken , use slf4j instead. Then you simply put different implementations on your CLASSPTH. Also the SLF4J API is quite pleasent.
You should take a look at SLF4J . It is essentially a wrapper that allows the end user to drop in what ever logging library they want (for the most part).
While I have not tried, they even have a migrator tool that should help changing over your code to use it.
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.