i have multiple web applications (multiple war) in one instance of wildfly. Each web application read its log4j.properties file called webapp1.log4j.properties stored in WILDFLY_HOME/standalone/configuration directory when start with servlet called by:
<servlet>
<servlet-name>LoadPropertiesServlet</servlet-name>
<display-name>LoadPropertiesServlet</display-name>
<servlet-class>it.h2h.smart.identity.servlet.LoadPropertiesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
Here is LoadPropertiesServlet class:
public void init() throws ServletException {
log.debug("init()");
loadConfiguration();
}
private void loadConfiguration() {
...
log.debug("Loading log4j file " + wildfly_config_path + "/" + webapp_name + ".log4j.properties");
PropertyConfigurator.configure(wildfly_config_path + "/" + webapp_name + ".log4j.properties");
...
}
And this is my webapp1.log4j.properties:
log4j.logger.it=DEBUG,WEBAPP
log4j.appender.WEBAPP=org.apache.log4j.DailyRollingFileAppender
log4j.appender.WEBAPP.DatePattern='.'yyyy-MM-dd
log4j.appender.WEBAPP.File=/Users/gianca/WEBAPP.log
log4j.appender.WEBAPP.layout=org.apache.log4j.PatternLayout
log4j.appender.WEBAPP.datePattern=yyyy-MM-dd
log4j.appender.WEBAPP.layout.ConversionPattern=%d %-5p %c:%L %x - %m%n
log4j.appender.WEBAPP.MaxBackupIndex = 10
So, when is deployed only one War into wildfly there is no problem, but when i deploy more than one War with different name with the same structure, all my logger of all War file deployed write on the last filename defined.
So, using the code above, if i deploy another webapp called Webapp2.war that load webapp2.log4j.properties that want write on other path different by webapp1:
log4j.logger.it=DEBUG,WEBAPP
log4j.appender.WEBAPP=org.apache.log4j.DailyRollingFileAppender
log4j.appender.WEBAPP.DatePattern='.'yyyy-MM-dd
log4j.appender.WEBAPP.File=/Users/otherpath/WEBAPP.log
log4j.appender.WEBAPP.layout=org.apache.log4j.PatternLayout
log4j.appender.WEBAPP.datePattern=yyyy-MM-dd
log4j.appender.WEBAPP.layout.ConversionPattern=%d %-5p %c:%L %x - %m%n
log4j.appender.WEBAPP.MaxBackupIndex = 10
the previous webapp1.war and this last will write logs into the /Users/otherpath/WEBAPP.log all together.
I'm using log4j-1.2.17.jar library inside each war file.
I try to change the log4j appender name of each log4j.properties like WEBAPP1 and WEBAPP2 without results.
There is a way to solve it ? Thanks