I have some problem with log4j2 configuration for war application on Wildfly 10.1 application server. I have the following log4j2.xml file (located in WEB-INF directory) :
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Properties>
<Property name="logDir">${sys:jboss.server.log.dir}</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<RollingRandomAccessFile
name="FileLogger"
fileName="${logDir}/${sys:loggerFileName}.log"
filePattern="${logDir}/$${date:yyyy-MM}/${sys:loggerFileName}-%d{yyyy-MM-dd}-%i.log.zip">
<PatternLayout pattern="%d{HH:mm:ss,SSS} %-5level [%t] %logger{36} - %msg%n"/>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="128MB" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${logDir}" maxDepth="2">
<IfFileName glob="*/${sys:loggerFileName}-*.log.zip" />
<IfLastModified age="30d" />
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="FileLogger"/>
</Root>
</Loggers>
I want to deploy several instance of this application on Wildfly. Each will have own deployement name and runtime name like it shown in screenshots below
When the application is deployed I replace value for "loggerFileName" property like this:
@WebListener
public class ServletContextInitializer implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
String loggerFileName = getLoggerFileNameForContext(servletContext);
System.setProperty("loggerFileName", loggerFileName);
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
ctx.reconfigure();
}
@Override
public void contextDestroyed(ServletContextEvent contextEvent) {
}
private String getLoggerFileNameForContext(ServletContext servletContext) {
String contextPath = servletContext.getContextPath();
return removeNonAlphaNumericCharsFromString(contextPath);
}
private String removeNonAlphaNumericCharsFromString(String input) {
return input.replaceAll("[^A-Za-z0-9 ]", "");
}
}
If applications are deployed one after another the log files are created correctly. But when I stop Wildfly then delete logs and next I launch Wildfly in some cases the log file is not created at all for one of the instances.
Can someone suggest me what can be wrong? Is System.setProperty() is shared by all instances of applications or not.
Thanks in advance for help.
Aucun commentaire:
Enregistrer un commentaire