RollingFileAppender + DirectWriteRolloverStrategy does not rollover file

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

RollingFileAppender + DirectWriteRolloverStrategy does not rollover file

Benjamin Asbach
Hej!

Currently I try to configure log4j2 to:
* create a log in a folder with dates: e.h.
2020_04_27/messages.20200427_13_39_01.log
* limit the log size to 250MB
(* use a custom layout)
(* rollover every day)

But I'm already stuck with the first two bullets


```
appender.msglog.type = RollingFile
appender.msglog.name = localmsglog
appender.msglog.filePattern =
/tmp/msg-${date:yyyy_MM_dd}/nps-message-${date:yyyy_MM_dd_HH_mm_ss}.log
appender.msglog.layout.type = log4j1xmllayout
appender.msglog.policies.type = Policies
appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
appender.msglog.policies.size.size = 250MB
appender.msglog.strategy.type = DirectWriteRolloverStrategy
```
Basically the log is created in the correct folder and with the correct
name. But the file is not rolled after 250MB .

I digged a little bit into the source and recognized that the
`DirectWriteRolloverStrategy` does not get the pattern, but the current
log file name, so it does not contain the `filePattern` at all.
Now I'm unsure if this is a bug or a configuration issue.

Thanks in advance
Benjamin

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

Reply | Threaded
Open this post in threaded view
|

Re: RollingFileAppender + DirectWriteRolloverStrategy does not rollover file

Benjamin Asbach
I guess I found a solution:

```
appender.msglog.type = RollingFile
appender.msglog.name = localmsglog
appender.msglog.filePattern =
/tmp/msg-%d{yyyy_MM_dd}/nps-message-%d{yyyy_MM_dd_HH_mm_ss}.log
appender.msglog.layout.type = log4j1xmllayout
appender.msglog.policies.type = Policies
appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
appender.msglog.policies.size.size = 250MB
```

Sorry for noise.
Benjamin


On 2020-04-27 16:24, Benjamin Asbach wrote:

> Hej!
>
> Currently I try to configure log4j2 to:
> * create a log in a folder with dates: e.h.
> 2020_04_27/messages.20200427_13_39_01.log
> * limit the log size to 250MB
> (* use a custom layout)
> (* rollover every day)
>
> But I'm already stuck with the first two bullets
>
>
> ```
> appender.msglog.type = RollingFile
> appender.msglog.name = localmsglog
> appender.msglog.filePattern =
> /tmp/msg-${date:yyyy_MM_dd}/nps-message-${date:yyyy_MM_dd_HH_mm_ss}.log
> appender.msglog.layout.type = log4j1xmllayout
> appender.msglog.policies.type = Policies
> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
> appender.msglog.policies.size.size = 250MB
> appender.msglog.strategy.type = DirectWriteRolloverStrategy
> ```
> Basically the log is created in the correct folder and with the
> correct name. But the file is not rolled after 250MB .
>
> I digged a little bit into the source and recognized that the
> `DirectWriteRolloverStrategy` does not get the pattern, but the
> current log file name, so it does not contain the `filePattern` at
> all.
> Now I'm unsure if this is a bug or a configuration issue.
>
> Thanks in advance
> Benjamin
>
> ---------------------------------------------------------------------
> 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: RollingFileAppender + DirectWriteRolloverStrategy does not rollover file

Benjamin Asbach
I guess I've been glad to early.

```
appender.msglog.type = RollingFile
appender.msglog.name = localmsglog
appender.msglog.filePattern =
/tmp/msg-%d{yyyy_MM_dd}/nps-message-%d{yyyy_MM_dd_HH_mm_ss}.log
appender.msglog.layout.type = log4j1xmllayout
appender.msglog.policies.type = Policies
appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
appender.msglog.policies.size.size = 250MB
```
Is rolling the file as expected.

I now tried to configure a nightly roll.

by adding  `appender.msglog.policies.cron.type = CronTriggeringPolicy`.
I also tried `appender.msglog.policies.time.type =
TimeBasedTriggeringPolicy`. Both results into a single log file
`msg-2020_04_27_00_00_00-0.log` and size based logging stops working.

Any ideas? Maybe I misunderstand some basic concept?

Thanks in advance
Benjamin

On 2020-04-27 17:47, Benjamin Asbach wrote:

> I guess I found a solution:
>
> ```
> appender.msglog.type = RollingFile
> appender.msglog.name = localmsglog
> appender.msglog.filePattern =
> /tmp/msg-%d{yyyy_MM_dd}/nps-message-%d{yyyy_MM_dd_HH_mm_ss}.log
> appender.msglog.layout.type = log4j1xmllayout
> appender.msglog.policies.type = Policies
> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
> appender.msglog.policies.size.size = 250MB
> ```
>
> Sorry for noise.
> Benjamin
>
>
> On 2020-04-27 16:24, Benjamin Asbach wrote:
>> Hej!
>>
>> Currently I try to configure log4j2 to:
>> * create a log in a folder with dates: e.h.
>> 2020_04_27/messages.20200427_13_39_01.log
>> * limit the log size to 250MB
>> (* use a custom layout)
>> (* rollover every day)
>>
>> But I'm already stuck with the first two bullets
>>
>>
>> ```
>> appender.msglog.type = RollingFile
>> appender.msglog.name = localmsglog
>> appender.msglog.filePattern =
>> /tmp/msg-${date:yyyy_MM_dd}/nps-message-${date:yyyy_MM_dd_HH_mm_ss}.log
>> appender.msglog.layout.type = log4j1xmllayout
>> appender.msglog.policies.type = Policies
>> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
>> appender.msglog.policies.size.size = 250MB
>> appender.msglog.strategy.type = DirectWriteRolloverStrategy
>> ```
>> Basically the log is created in the correct folder and with the
>> correct name. But the file is not rolled after 250MB .
>>
>> I digged a little bit into the source and recognized that the
>> `DirectWriteRolloverStrategy` does not get the pattern, but the
>> current log file name, so it does not contain the `filePattern` at
>> all.
>> Now I'm unsure if this is a bug or a configuration issue.
>>
>> Thanks in advance
>> Benjamin
>>
>> ---------------------------------------------------------------------
>> 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]

Reply | Threaded
Open this post in threaded view
|

Re: RollingFileAppender + DirectWriteRolloverStrategy does not rollover file

Ralph Goers
The %d pattern only applies to time based rollovers. If you want the time in a size based rollover pattern then use the date lookup  

filePattern=/tmp/msg-$${date:yyyy_MM_dd}/nps-message-$${date:yyyy_MM_dd_HH_mm_ss}.log

Ralph

> On Apr 27, 2020, at 10:39 AM, Benjamin Asbach <[hidden email]> wrote:
>
> I guess I've been glad to early.
>
> ```
> appender.msglog.type = RollingFile
> appender.msglog.name = localmsglog
> appender.msglog.filePattern = /tmp/msg-%d{yyyy_MM_dd}/nps-message-%d{yyyy_MM_dd_HH_mm_ss}.log
> appender.msglog.layout.type = log4j1xmllayout
> appender.msglog.policies.type = Policies
> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
> appender.msglog.policies.size.size = 250MB
> ```
> Is rolling the file as expected.
>
> I now tried to configure a nightly roll.
>
> by adding  `appender.msglog.policies.cron.type = CronTriggeringPolicy`. I also tried `appender.msglog.policies.time.type = TimeBasedTriggeringPolicy`. Both results into a single log file `msg-2020_04_27_00_00_00-0.log` and size based logging stops working.
>
> Any ideas? Maybe I misunderstand some basic concept?
>
> Thanks in advance
> Benjamin
>
> On 2020-04-27 17:47, Benjamin Asbach wrote:
>> I guess I found a solution:
>> ```
>> appender.msglog.type = RollingFile
>> appender.msglog.name = localmsglog
>> appender.msglog.filePattern =
>> /tmp/msg-%d{yyyy_MM_dd}/nps-message-%d{yyyy_MM_dd_HH_mm_ss}.log
>> appender.msglog.layout.type = log4j1xmllayout
>> appender.msglog.policies.type = Policies
>> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
>> appender.msglog.policies.size.size = 250MB
>> ```
>> Sorry for noise.
>> Benjamin
>> On 2020-04-27 16:24, Benjamin Asbach wrote:
>>> Hej!
>>> Currently I try to configure log4j2 to:
>>> * create a log in a folder with dates: e.h.
>>> 2020_04_27/messages.20200427_13_39_01.log
>>> * limit the log size to 250MB
>>> (* use a custom layout)
>>> (* rollover every day)
>>> But I'm already stuck with the first two bullets
>>> ```
>>> appender.msglog.type = RollingFile
>>> appender.msglog.name = localmsglog
>>> appender.msglog.filePattern =
>>> /tmp/msg-${date:yyyy_MM_dd}/nps-message-${date:yyyy_MM_dd_HH_mm_ss}.log
>>> appender.msglog.layout.type = log4j1xmllayout
>>> appender.msglog.policies.type = Policies
>>> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
>>> appender.msglog.policies.size.size = 250MB
>>> appender.msglog.strategy.type = DirectWriteRolloverStrategy
>>> ```
>>> Basically the log is created in the correct folder and with the
>>> correct name. But the file is not rolled after 250MB .
>>> I digged a little bit into the source and recognized that the
>>> `DirectWriteRolloverStrategy` does not get the pattern, but the
>>> current log file name, so it does not contain the `filePattern` at
>>> all.
>>> Now I'm unsure if this is a bug or a configuration issue.
>>> Thanks in advance
>>> Benjamin
>>> ---------------------------------------------------------------------
>>> 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]
>
>



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

Reply | Threaded
Open this post in threaded view
|

Re: RollingFileAppender + DirectWriteRolloverStrategy does not rollover file

Benjamin Asbach
Hi Ralph,

thanks for taking some time.

Basically I want a log which rotates at midnight and is limited in file
size. So I'd expect that these files are generated:

/2020_04_27/msg-2020_04_27-12_17_00.log (application started)
/2020_04_27/msg-2020_04_27-18_13_30.log (log file exceed 250MB)
/2020_04_28/msg-2020_04_28-00_00_00.log (next day)

I guess the suggested pattern isn't the entire solution since with

* TimeBasedTriggeringPolicy) Is now invalid due the missing %d
* CronTriggeringPolicy) Just creates one big log file
`msg-2020_04_27-00_00_00.log` ignoring the file limitations

Thanks
Benjamin


On 2020-04-27 20:28, Ralph Goers wrote:

> The %d pattern only applies to time based rollovers. If you want the
> time in a size based rollover pattern then use the date lookup
>
> filePattern=/tmp/msg-$${date:yyyy_MM_dd}/nps-message-$${date:yyyy_MM_dd_HH_mm_ss}.log
>
> Ralph
>
>> On Apr 27, 2020, at 10:39 AM, Benjamin Asbach <[hidden email]>
>> wrote:
>>
>> I guess I've been glad to early.
>>
>> ```
>> appender.msglog.type = RollingFile
>> appender.msglog.name = localmsglog
>> appender.msglog.filePattern =
>> /tmp/msg-%d{yyyy_MM_dd}/nps-message-%d{yyyy_MM_dd_HH_mm_ss}.log
>> appender.msglog.layout.type = log4j1xmllayout
>> appender.msglog.policies.type = Policies
>> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
>> appender.msglog.policies.size.size = 250MB
>> ```
>> Is rolling the file as expected.
>>
>> I now tried to configure a nightly roll.
>>
>> by adding  `appender.msglog.policies.cron.type =
>> CronTriggeringPolicy`. I also tried
>> `appender.msglog.policies.time.type = TimeBasedTriggeringPolicy`. Both
>> results into a single log file `msg-2020_04_27_00_00_00-0.log` and
>> size based logging stops working.
>>
>> Any ideas? Maybe I misunderstand some basic concept?
>>
>> Thanks in advance
>> Benjamin
>>
>> On 2020-04-27 17:47, Benjamin Asbach wrote:
>>> I guess I found a solution:
>>> ```
>>> appender.msglog.type = RollingFile
>>> appender.msglog.name = localmsglog
>>> appender.msglog.filePattern =
>>> /tmp/msg-%d{yyyy_MM_dd}/nps-message-%d{yyyy_MM_dd_HH_mm_ss}.log
>>> appender.msglog.layout.type = log4j1xmllayout
>>> appender.msglog.policies.type = Policies
>>> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
>>> appender.msglog.policies.size.size = 250MB
>>> ```
>>> Sorry for noise.
>>> Benjamin
>>> On 2020-04-27 16:24, Benjamin Asbach wrote:
>>>> Hej!
>>>> Currently I try to configure log4j2 to:
>>>> * create a log in a folder with dates: e.h.
>>>> 2020_04_27/messages.20200427_13_39_01.log
>>>> * limit the log size to 250MB
>>>> (* use a custom layout)
>>>> (* rollover every day)
>>>> But I'm already stuck with the first two bullets
>>>> ```
>>>> appender.msglog.type = RollingFile
>>>> appender.msglog.name = localmsglog
>>>> appender.msglog.filePattern =
>>>> /tmp/msg-${date:yyyy_MM_dd}/nps-message-${date:yyyy_MM_dd_HH_mm_ss}.log
>>>> appender.msglog.layout.type = log4j1xmllayout
>>>> appender.msglog.policies.type = Policies
>>>> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
>>>> appender.msglog.policies.size.size = 250MB
>>>> appender.msglog.strategy.type = DirectWriteRolloverStrategy
>>>> ```
>>>> Basically the log is created in the correct folder and with the
>>>> correct name. But the file is not rolled after 250MB .
>>>> I digged a little bit into the source and recognized that the
>>>> `DirectWriteRolloverStrategy` does not get the pattern, but the
>>>> current log file name, so it does not contain the `filePattern` at
>>>> all.
>>>> Now I'm unsure if this is a bug or a configuration issue.
>>>> Thanks in advance
>>>> Benjamin
>>>> ---------------------------------------------------------------------
>>>> 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]
>>
>>
>
>
>
> ---------------------------------------------------------------------
> 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: RollingFileAppender + DirectWriteRolloverStrategy does not rollover file

Ralph Goers
If you want both time and size then you need one %d pattern that reflects the interval for when you want rotation to occur - namely yyyy_MM_dd. Normally you would use %I in the pattern to increment a counter during the interval. But I suspect if you use ${date} in the file name of the pattern and the granularity is smaller than the time it will take to generate enough records to perform a rollover you should be ok.

Ralph

> On Apr 27, 2020, at 1:51 PM, Benjamin Asbach <[hidden email]> wrote:
>
> Hi Ralph,
>
> thanks for taking some time.
>
> Basically I want a log which rotates at midnight and is limited in file size. So I'd expect that these files are generated:
>
> /2020_04_27/msg-2020_04_27-12_17_00.log (application started)
> /2020_04_27/msg-2020_04_27-18_13_30.log (log file exceed 250MB)
> /2020_04_28/msg-2020_04_28-00_00_00.log (next day)
>
> I guess the suggested pattern isn't the entire solution since with
>
> * TimeBasedTriggeringPolicy) Is now invalid due the missing %d
> * CronTriggeringPolicy) Just creates one big log file `msg-2020_04_27-00_00_00.log` ignoring the file limitations
>
> Thanks
> Benjamin
>
>
> On 2020-04-27 20:28, Ralph Goers wrote:
>> The %d pattern only applies to time based rollovers. If you want the
>> time in a size based rollover pattern then use the date lookup
>> filePattern=/tmp/msg-$${date:yyyy_MM_dd}/nps-message-$${date:yyyy_MM_dd_HH_mm_ss}.log
>> Ralph
>>> On Apr 27, 2020, at 10:39 AM, Benjamin Asbach <[hidden email]> wrote:
>>> I guess I've been glad to early.
>>> ```
>>> appender.msglog.type = RollingFile
>>> appender.msglog.name = localmsglog
>>> appender.msglog.filePattern = /tmp/msg-%d{yyyy_MM_dd}/nps-message-%d{yyyy_MM_dd_HH_mm_ss}.log
>>> appender.msglog.layout.type = log4j1xmllayout
>>> appender.msglog.policies.type = Policies
>>> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
>>> appender.msglog.policies.size.size = 250MB
>>> ```
>>> Is rolling the file as expected.
>>> I now tried to configure a nightly roll.
>>> by adding  `appender.msglog.policies.cron.type = CronTriggeringPolicy`. I also tried `appender.msglog.policies.time.type = TimeBasedTriggeringPolicy`. Both results into a single log file `msg-2020_04_27_00_00_00-0.log` and size based logging stops working.
>>> Any ideas? Maybe I misunderstand some basic concept?
>>> Thanks in advance
>>> Benjamin
>>> On 2020-04-27 17:47, Benjamin Asbach wrote:
>>>> I guess I found a solution:
>>>> ```
>>>> appender.msglog.type = RollingFile
>>>> appender.msglog.name = localmsglog
>>>> appender.msglog.filePattern =
>>>> /tmp/msg-%d{yyyy_MM_dd}/nps-message-%d{yyyy_MM_dd_HH_mm_ss}.log
>>>> appender.msglog.layout.type = log4j1xmllayout
>>>> appender.msglog.policies.type = Policies
>>>> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
>>>> appender.msglog.policies.size.size = 250MB
>>>> ```
>>>> Sorry for noise.
>>>> Benjamin
>>>> On 2020-04-27 16:24, Benjamin Asbach wrote:
>>>>> Hej!
>>>>> Currently I try to configure log4j2 to:
>>>>> * create a log in a folder with dates: e.h.
>>>>> 2020_04_27/messages.20200427_13_39_01.log
>>>>> * limit the log size to 250MB
>>>>> (* use a custom layout)
>>>>> (* rollover every day)
>>>>> But I'm already stuck with the first two bullets
>>>>> ```
>>>>> appender.msglog.type = RollingFile
>>>>> appender.msglog.name = localmsglog
>>>>> appender.msglog.filePattern =
>>>>> /tmp/msg-${date:yyyy_MM_dd}/nps-message-${date:yyyy_MM_dd_HH_mm_ss}.log
>>>>> appender.msglog.layout.type = log4j1xmllayout
>>>>> appender.msglog.policies.type = Policies
>>>>> appender.msglog.policies.size.type = SizeBasedTriggeringPolicy
>>>>> appender.msglog.policies.size.size = 250MB
>>>>> appender.msglog.strategy.type = DirectWriteRolloverStrategy
>>>>> ```
>>>>> Basically the log is created in the correct folder and with the
>>>>> correct name. But the file is not rolled after 250MB .
>>>>> I digged a little bit into the source and recognized that the
>>>>> `DirectWriteRolloverStrategy` does not get the pattern, but the
>>>>> current log file name, so it does not contain the `filePattern` at
>>>>> all.
>>>>> Now I'm unsure if this is a bug or a configuration issue.
>>>>> Thanks in advance
>>>>> Benjamin
>>>>> ---------------------------------------------------------------------
>>>>> 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]
>> ---------------------------------------------------------------------
>> 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]