Reputation: 99
OS : Linux Weblogic: 10.3.6.0 JDK: 1.7.0_55
Recently we have migrated from log4j 1.x to 2.6.1 I am seeing loggers are being written to rolled file along with main log file. Also rolled file size less given given restricted size which is 50MB. This is observed mainly if I am pushing load of 400k records. PFA log4j xml.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG" >
<Properties>
<Property name="theHostName">${hostName}</Property>
</Properties>
<!-- bufferedIO=true by default, bufferSize=8192bytes
-->
<Appenders>
<RollingFile name="FILE" filename="${sys:weblogic.Name}.log" filepattern="${sys:weblogic.Name}.log.%i" append="false" >
<PatternLayout pattern="[%-5p][%d{yyyy-MM-dd HH:mm:ss,SSS}][${sys:weblogic.Name}:${hostName}][%t][%X{MessageInfo}][%c{1}:%M:%L][%msg]%n" />
<Policies>
<SizeBasedTriggeringPolicy size="50 MB" />
</Policies>
<DefaultRolloverStrategy min="1" max="100" fileIndex="min"/>
</RollingFile>
</Appenders>
<Loggers>
<Logger level="DEBUG" includeLocation="true">
<AppenderRef ref="FILE"/>
</Logger>
<Root level="INFO" includeLocation="true">
<AppenderRef ref="FILE"/>
</Root>
<!-- Package specific log level defines -->
<logger name="org.springframework">
<level value="WARN" />
</logger>
<logger name="org.jboss">
<level value="WARN" />
</logger>
<logger name="org.hibernate">
<level value="OFF" />
</logger>
<logger name="com.company.project.eligibility">
<level value="WARN" />
</logger>
</Loggers>
</Configuration>
Please suggest.
Upvotes: 3
Views: 1743
Reputation: 36754
If you have multiple applications writing to the same file, you need to take special care with Log4j2 (this is different than Log4j 1.x).
In order to successfully log to the same file from multiple applications, these applications need to share the same LoggerContext. You can achieve this by putting the log4j2 jar files in the weblogic shared lib so that the Log4j2 classes are loaded by the same classloader.
If the log4j2 jars are bundled inside the WAR or EAR archive, the log4j2 classes will be loaded by the separate application classloader and they will end up with a separate LoggerContext. If multiple applications have a separate LoggerContext they are not aware of each other which may give strange results on file rollover.
Related documentation: Logging Separation and Web Applications and JSPs. (Your application may not be a web application but if it is running in Weblogic the same principles apply.)
Upvotes: 3