combine log4j2 SizeBasedTriggeringPolicy with CronTriggeringPolicy

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

combine log4j2 SizeBasedTriggeringPolicy with CronTriggeringPolicy

Franz van Betteraey
Hi all,
 
I try to combine a log4j2 SizeBasedTriggeringPolicy with a CronTriggeringPolicy to roll over a file either at midnight or every 20MB (every minute or every 100KB for testing) like this:
 
<RollingFile name="RollingFile"
    filePattern="target/logs/foobar-%d{yyyyMMdd-HHmmss}{UTC}.log">
    <Layout type="PatternLayout" pattern="%date{DEFAULT} | %message%n" />
    <Policies>
        <SizeBasedTriggeringPolicy size="100KB" />
        <CronTriggeringPolicy schedule="0 * * * * ? *" evaluateOnStartup="true" />
    </Policies>
</RollingFile>
 
Unfortunately only the CronTriggeringPolicy seems to work in this combination. No roll over is done when the file size limit is reached. Removing the 'CronTriggeringPolicy ' from the configuration will let the roll over happen every 100KB as expected.
 
Beware of the fact that I can not use the TimeBasedTriggeringPolicy because I need to have a second accurate date in the file name pattern but I want to roll over just every day (or every minute for testing here).
Is this (unabalibility of combining CronTriggeringPolicy with other policies) a know bug or limitation when using the CronTriggeringPolicy?
 
I also asked this question on SO but without response so far:
https://stackoverflow.com/q/54406364/367285
 
Any help would be appriciated.
 
Thanks ab best regards,
  Franz
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Aw: combine log4j2 SizeBasedTriggeringPolicy with CronTriggeringPolicy

Franz van Betteraey
I provided a running example project.
https://github.com/FrVaBe/logging

Just run the Main class and monitor the files that are generated in target/logs.
In the setup of this project they roll over every 30 seconds although they should already rotate when the size of 100KB is reached (which will not last 30 seconds on my computer).
 
 
 

Gesendet: Dienstag, 29. Januar 2019 um 09:45 Uhr
Von: "Franz van Betteraey" <[hidden email]>
An: [hidden email]
Betreff: combine log4j2 SizeBasedTriggeringPolicy with CronTriggeringPolicy
Hi all,
 
I try to combine a log4j2 SizeBasedTriggeringPolicy with a CronTriggeringPolicy to roll over a file either at midnight or every 20MB (every minute or every 100KB for testing) like this:
 
<RollingFile name="RollingFile"
    filePattern="target/logs/foobar-%d{yyyyMMdd-HHmmss}{UTC}.log">
    <Layout type="PatternLayout" pattern="%date{DEFAULT} | %message%n" />
    <Policies>
        <SizeBasedTriggeringPolicy size="100KB" />
        <CronTriggeringPolicy schedule="0 * * * * ? *" evaluateOnStartup="true" />
    </Policies>
</RollingFile>
 
Unfortunately only the CronTriggeringPolicy seems to work in this combination. No roll over is done when the file size limit is reached. Removing the 'CronTriggeringPolicy ' from the configuration will let the roll over happen every 100KB as expected.
 
Beware of the fact that I can not use the TimeBasedTriggeringPolicy because I need to have a second accurate date in the file name pattern but I want to roll over just every day (or every minute for testing here).
Is this (unabalibility of combining CronTriggeringPolicy with other policies) a know bug or limitation when using the CronTriggeringPolicy?
 
I also asked this question on SO but without response so far:
https://stackoverflow.com/q/54406364/367285
 
Any help would be appriciated.
 
Thanks ab best regards,
  Franz
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: combine log4j2 SizeBasedTriggeringPolicy with CronTriggeringPolicy

Ralph Goers
Thanks for the report. I tested your sample project and the file pattern does not contain a “%I”. Without this files will get overwritten. But in the course of testing this after adding the %I I discovered that rolling was creating files with the wrong name. I have fixed that. Please try the latest on the release-2.x branch.

Ralph

> On Jan 29, 2019, at 3:42 AM, Franz van Betteraey <[hidden email]> wrote:
>
> I provided a running example project.
> https://github.com/FrVaBe/logging
>
> Just run the Main class and monitor the files that are generated in target/logs.
> In the setup of this project they roll over every 30 seconds although they should already rotate when the size of 100KB is reached (which will not last 30 seconds on my computer).
>  
>  
>  
>
> Gesendet: Dienstag, 29. Januar 2019 um 09:45 Uhr
> Von: "Franz van Betteraey" <[hidden email]>
> An: [hidden email]
> Betreff: combine log4j2 SizeBasedTriggeringPolicy with CronTriggeringPolicy
> Hi all,
>  
> I try to combine a log4j2 SizeBasedTriggeringPolicy with a CronTriggeringPolicy to roll over a file either at midnight or every 20MB (every minute or every 100KB for testing) like this:
>  
> <RollingFile name="RollingFile"
>     filePattern="target/logs/foobar-%d{yyyyMMdd-HHmmss}{UTC}.log">
>     <Layout type="PatternLayout" pattern="%date{DEFAULT} | %message%n" />
>     <Policies>
>         <SizeBasedTriggeringPolicy size="100KB" />
>         <CronTriggeringPolicy schedule="0 * * * * ? *" evaluateOnStartup="true" />
>     </Policies>
> </RollingFile>
>  
> Unfortunately only the CronTriggeringPolicy seems to work in this combination. No roll over is done when the file size limit is reached. Removing the 'CronTriggeringPolicy ' from the configuration will let the roll over happen every 100KB as expected.
>  
> Beware of the fact that I can not use the TimeBasedTriggeringPolicy because I need to have a second accurate date in the file name pattern but I want to roll over just every day (or every minute for testing here).
> Is this (unabalibility of combining CronTriggeringPolicy with other policies) a know bug or limitation when using the CronTriggeringPolicy?
>  
> I also asked this question on SO but without response so far:
> https://stackoverflow.com/q/54406364/367285
>  
> Any help would be appriciated.
>  
> Thanks ab best regards,
>   Franz
>  
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>  
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]