You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Rick <ri...@gmail.com> on 2022/09/02 04:21:04 UTC

Difference between the Date lookup $${date:yyyy-MM} and the Format Specifier %d{yyyy-MM}?

Hi,

I am new to Log4j2, and I am a little bit confused with the Date lookup
$${date:yyyy-MM} and the Format Specifier %d{yyyy-MM}.
Please see the following configuration:

<RollingRandomAccessFile name="log2file" fileName="logs/app.log"
filePattern="logs/*$${date:yyyy-MM}*/app-*%d{MM-dd-yyyy}*-%i.log.gz">


-- 

Sincerely,

*Rick Qin*
Email: rickqinj@gmail.com

Re: Difference between the Date lookup $${date:yyyy-MM} and the Format Specifier %d{yyyy-MM}?

Posted by Matt Sicker <bo...@gmail.com>.
There’s also the fact that lookups are usable in layouts that don’t reuse pattern layout components. Note that there are also differences in how objects are allocated for different plugins when GC-free logging is a concern.

—
Matt Sicker

> On Sep 2, 2022, at 00:47, Piotr P. Karwasz <pi...@gmail.com> wrote:
> 
> Hi Rick,
> I gave a longer answer about this a couple of months ago on StackOverflow:
> 
> https://stackoverflow.com/q/71862896/11748454
> 
> Basically the delayed lookup `$${date:...}` uses the current time,
> when the rollover occurs, while the pattern `%d{...}` uses the date of
> the previous rollover.
> 
> A `RollingFileAppender` also uses the first (and hopefully only)
> pattern it finds to determine the rollover frequency.
> 
> Piotr
> 
>> On Fri, 2 Sept 2022 at 06:21, Rick <ri...@gmail.com> wrote:
>> 
>> Hi,
>> 
>> I am new to Log4j2, and I am a little bit confused with the Date lookup
>> $${date:yyyy-MM} and the Format Specifier %d{yyyy-MM}.
>> Please see the following configuration:
>> 
>> <RollingRandomAccessFile name="log2file" fileName="logs/app.log"
>> filePattern="logs/*$${date:yyyy-MM}*/app-*%d{MM-dd-yyyy}*-%i.log.gz">
>> 
>> 
>> --
>> 
>> Sincerely,
>> 
>> *Rick Qin*
>> Email: rickqinj@gmail.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 

Re: Difference between the Date lookup $${date:yyyy-MM} and the Format Specifier %d{yyyy-MM}?

Posted by "Piotr P. Karwasz" <pi...@gmail.com>.
Hi Rick,
I gave a longer answer about this a couple of months ago on StackOverflow:

https://stackoverflow.com/q/71862896/11748454

Basically the delayed lookup `$${date:...}` uses the current time,
when the rollover occurs, while the pattern `%d{...}` uses the date of
the previous rollover.

A `RollingFileAppender` also uses the first (and hopefully only)
pattern it finds to determine the rollover frequency.

Piotr

On Fri, 2 Sept 2022 at 06:21, Rick <ri...@gmail.com> wrote:
>
> Hi,
>
> I am new to Log4j2, and I am a little bit confused with the Date lookup
> $${date:yyyy-MM} and the Format Specifier %d{yyyy-MM}.
> Please see the following configuration:
>
> <RollingRandomAccessFile name="log2file" fileName="logs/app.log"
> filePattern="logs/*$${date:yyyy-MM}*/app-*%d{MM-dd-yyyy}*-%i.log.gz">
>
>
> --
>
> Sincerely,
>
> *Rick Qin*
> Email: rickqinj@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org