Another interesting situation. We want to have one log4j.properties file. We also want all the classes to use one status logger. However, if the software is run on the web server (via servlets) we want the information to go into the web server log. If it is run on a server (via Java main) we want the information to go into the syslog. (We have many servers both web and not, plus numerous software environments, not to mention different browsers, etc. The Web Architect wants one "logging system" that does everything for the software regardless of how it is run.)
I have set up an appender for the web server log. Actually quite simple. The syslogAppender already exists. Now the delima. The desired logging behavior is that if started from a servlet the information should only be written to the web server log. If started from a Java main, the information should only be written to the syslog. Currently, I have a prototype set up. The log4j.properties defines a status logger with two associated appenders - webServerAppender and syslogAppender. (Actually many more loggers and appenders but the situation is only with these). I have created two constructors for the status logger. The one has the servlet req passed in and the other does not. The servlet constructor removes the syslogAppender and the non-servlet constructor removes the webServerAppender. This works but I am wondering is there a better way of doing this? Thanks, Adam