[ 
https://issues.apache.org/jira/browse/LOG4J2-2137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16776123#comment-16776123
 ] 

Ralph Goers edited comment on LOG4J2-2137 at 2/24/19 5:17 AM:
--------------------------------------------------------------

You are using the SizeBasedTriggeringPolicy without a "%i" pattern in the file 
pattern, but you have a granularity of 1 second. The max attribute on the 
DefaultRolloverStrategy only applies to patterns with a %i and only to a single 
"group" of files. For example, if you had a %i along with a granularity of an 
hour then the file would roll over every time it hit 1K and would create a new 
file with an incremented index. It would start deleting files within that group 
once the number of files in that group hits the max amount. Once the hour is up 
a new group would be created with the time for that hour.

I should also point out that without a %i in the pattern the 
SizeBasedTriggeringPolicy would cause the archive file to be overridden if it 
rolls over faster than the time granularity. In your configuration that would 
happen if you write more than 1K in a second.

In short, if you want to roll by size always include a %i in the pattern. I 
also recommend you follow Remko's advice and use the DeleteAction.

If this answers all your questions please feel free to close this issue.


was (Author: [email protected]):
You are using the SizeBasedTriggeringPolicy without a "%i" pattern in the file 
pattern, but you have a granularity of 1 second. The max attribute on the 
DefaultRolloverStrategy only applies to patterns with a %i and only to a single 
"group" of files. For example, if you had a %i along with a granularity of an 
hour then the file would roll over every time it hit 1K and would create a new 
file with an incremented index. It would start deleting files within that group 
once the number of files in that group hits the max amount. Once the hour is up 
a new group would be created with the time for that hour.

I should also point out that without a %i in the pattern the 
SizeBasedTriggeringPolicy would cause the archive file to be overridden if it 
rolls over faster than the time granularity. In your configuration that would 
happen if you write more than 1K in a second.

In short, if you want to roll by size always include a %i in the pattern. I 
also recommend you follow Remko's advice and use the DeleteAction.

> SizeBasedTriggeringPolicy with DefaultRolloverStrategy is not working
> ---------------------------------------------------------------------
>
>                 Key: LOG4J2-2137
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2137
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.3
>         Environment: Linux
> IBM J9 VM (build 2.4, J2RE 1.6.0 IBM J9 2.4 Linux x86-32 
> jvmxi3260-20080816_22093 (JIT enabled, AOT enabled)
>            Reporter: Ajay Pachlangia
>            Priority: Major
>              Labels: features
>             Fix For: 2.3
>
>
> Hi Team,
> I have used below given log4j file and expect my logs to be getting generated 
> up to size 1 MB with limit of 5 files but files are not reaching to the max 
> size and next files getting started written.
> 1048596 Dec 1 18:31 A-2017-12-01-3.log
> 449246  Dec 1 18:33 A-2017-12-01-1.log
> 1048636 Dec 1 18:32 A-2017-12-01-2.log
> 123424  Dec 1 18:33 A-2017-12-01-5.log
> 565972  Dec 1 18:33 A-2017-12-01-4.log
> 270800  Dec 1 18:33 A.log
> ---Log4j used ----
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration monitorInterval="5">
>     <Appenders>
> <RollingFile name="Online" fileName="My_Logs_Path/A.log" append="true" 
> immediateFlush="true" bufferedIO="false" 
> filePattern="My_Logs_Path/A-%d{yyyy-MM-dd}-%i.log">
>                       <PatternLayout>
>                               
> <pattern>|%-5p|%d{yyyy-MM-dd|HH:mm:ss,SSS}|%X{InterfaceId}|%X{SeqNo}|%X{Ouid} 
> %X{srch1} 
> %X{BussRef}|${sys:hostname}|${sys:ApplicationComponent}|%X{ExternalRefSend}|%m||%C{6}:%L|%t%n</pattern>
>                       </PatternLayout>
>                       <Policies>
>                               <SizeBasedTriggeringPolicy size="1 MB" />
>                       </Policies>
>                       <DefaultRolloverStrategy max="5"/>
>                       <Filters>
>                               <ThresholdFilter level="FATAL" onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="ERROR" onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="WARN"  onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="INFO"  onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="DEBUG" onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>                                                
>                       </Filters>
>               </RollingFile>
>               
>                          <RollingFile name="abcd" 
> fileName="My_Logs_Path/B.log" append="true" immediateFlush="true" 
> bufferedIO="false" filePattern="My_Logs_Path/B-%d{yyyy-MM-dd}-%i.log">
>                       <PatternLayout>
>                               
> <pattern>|%-5p|%d{yyyy-MM-dd|HH:mm:ss,SSS}|%X{InterfaceId}|%X{SeqNo}|%X{Ouid} 
> %X{srch1} 
> %X{BussRef}|${sys:hostname}|${sys:ApplicationComponent}|%X{ExternalRefSend}|%m||%C{6}:%L|%t%n</pattern>
>                       </PatternLayout>
>                       <Policies>
>                               <SizeBasedTriggeringPolicy size="1 MB" />
>                       </Policies>
>                       <DefaultRolloverStrategy max="5"/>
>                       <Filters>
>                               <ThresholdFilter level="FATAL" onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="ERROR" onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="WARN"  onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="INFO"  onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="DEBUG" onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>                                                
>                       </Filters>
>               </RollingFile>
>          <RollingFile name="efgh" fileName="My_Logs_Path/C.log" append="true" 
> immediateFlush="true" bufferedIO="false" 
> filePattern="My_Logs_Path/C-%d{yyyy-MM-dd}-%i.log">
>                       <PatternLayout>
>                               
> <pattern>|%-5p|%d{yyyy-MM-dd|HH:mm:ss,SSS}|%X{InterfaceId}|%X{SeqNo}|%X{Ouid} 
> %X{srch1} 
> %X{BussRef}|${sys:hostname}|${sys:ApplicationComponent}|%X{ExternalRefSend}|%m||%C{6}:%L|%t%n</pattern>
>                       </PatternLayout>
>                       <Policies>
>                               <SizeBasedTriggeringPolicy size="1 MB" />
>                       </Policies>
>                       <DefaultRolloverStrategy max="5"/>
>                       <Filters>
>                               <ThresholdFilter level="FATAL" onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="ERROR" onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="WARN"  onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="INFO"  onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>
>                               <ThresholdFilter level="DEBUG" onMatch="ACCEPT" 
>   onMismatch="NEUTRAL"/>                                                
>                       </Filters>
>               </RollingFile>
>               
>               <RollingFile name="CHANNEL_STATUS" 
> fileName="My_Logs_Path/D.log" append="true" immediateFlush="true" 
> bufferedIO="false" filePattern="My_Logs_Path/D-%d{yyyy-MM-dd}-%i.log">
>                       <PatternLayout>
>                               
> <pattern>|%-5p|%d{yyyy-MM-dd|HH:mm:ss,SSS}|${sys:hostname}|${sys:ApplicationComponent}|%m||%C{6}:%L|%t%n</pattern>
>                       </PatternLayout>
>                       <Policies>
>                               <SizeBasedTriggeringPolicy size="1 MB" />
>                       </Policies>
>                       <DefaultRolloverStrategy max="5"/>
>               </RollingFile>
> </Appenders>
> <loggers>
>     <logger name="TTTT" level="DEBUG">
>               <appender-ref ref="Online"  level="DEBUG"/>
>       </logger>
>     <logger name="AAAA" level="DEBUG">
>               <appender-ref ref="abcd"  level="DEBUG"/>
>       </logger>
>       <logger name="BBBB" level="DEBUG" additivity="false">
>               <appender-ref ref="efgh"/>
>       </logger>
>       <logger name="CHANNEL_LOGGER" level="DEBUG" additivity="false">
>               <appender-ref ref="CHANNEL_STATUS" level="DEBUG"/>
>       </logger>
>       <logger name="org.springframework" level="OFF">
>       </logger>
> </loggers>
> </Configuration>



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to