I'm having this wierd issue with my log4JAppender.
Im using a dailyRollingFileAppender and the configuration for the same is as follows:
#---------------------------------------------------------------------------------------
# Log config for the Web
#---------------------------------------------------------------开发者_开发问答------------------------
log4j.appender.aWeb = org.apache.log4j.DailyRollingFileAppender
log4j.appender.aWeb.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.aWeb.file = @LOG_DIR@/web.log
log4j.appender.aWeb.layout = org.apache.log4j.PatternLayout
log4j.appender.aWeb.layout.ConversionPattern = [ %d [%t] %C{2}.%M():%L %X{USER_NAME}%x %-5p]: %m%n
Now , my main log file works just fine, the issue occurs with the daily rolled files that are being created.
The daily rolling file, does not have the full log, instead its truncated.
A few observations: 1. The truncation is not based on the length, i.e different files have different amount of logged data in them 2. Maybe , the number of log statements might be the same, i.e after 20 log statements the log is truncated , or maybe something similar.
I am not sure why this is happening, has someone already faced this issue, if not what might be the possible workarounds for the same.
Thanks
I haven't run in the issue you are encountering with the DailyRollingFileAppender but I would recommend the RollingFileAppender
in combination with the TimeBasedRollingPolicy
from the log4j extras package - http://logging.apache.org/log4j/companions/extras/index.html
This has been working fine for us. No issue with truncation. Sample config below.
# Define the appender which is the RollingFileAppender in the Log4j extras packages
log4j.appender.FILE=org.apache.log4j.rolling.RollingFileAppender
# Define a the RollingPolicy for this Appender
# More information at http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html
log4j.appender.FILE.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
# Define the active file name for this RollingPolicy this is the file were current log is placed
log4j.appender.FILE.RollingPolicy.ActiveFileName=@LOG_DIR@/web.log
# Define the file name for the rolling policy. This file location contains a pattern that specifies how often the file will roll over and if compression should occur or not.
log4j.appender.FILE.RollingPolicy.FileNamePattern=@LOG_DIR@/web.%d{yyyy-MM-dd}-00-00.log.gz
精彩评论