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 no jihun <je...@gmail.com> on 2015/07/31 02:26:46 UTC
Including current date postfix in fileName (log4j2)
Hello,
I want log4j to write at file which current date postfixed.
for example, if today is 2015-07-31
- expected file name created : logs/test.log.2015-07-31
- (not this one : logs/test.log)
when I use log4j I could do that by following.
<appender name="testLog"
class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="/home/logs/test.log.%d{yyyy-MM-dd}" />
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n" />
</layout>
</appender>
TimeBasedRollingPolicy is class in apache-log4j-extras.jar
This configuration make It's down dated log file at the beginning of
every new day.
How can I do this with* log4j2*'s org.apache.logging.log4j.core.appender.
RollingFileAppender?
Thanks!
Hun
Re: Including current date postfix in fileName (log4j2)
Posted by Ralph Goers <ra...@dslextreme.com>.
Yes, we have an enhancement request in Jira for that.
Ralph
> On Jul 30, 2015, at 7:16 PM, no jihun <je...@gmail.com> wrote:
>
> thank you for your concern
>
> but it seems like neither RollingFileAppender nor
> RollingRandomAccessFileAppender
> <https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingRandomAccessFileAppender>
> could
> not create currently appending file name with datePattern.
> just create fileName and moved with rolling pattern.
>
> with is configuration
> <RollingFile name="RollingFile" fileName="${log-path}/myexample.log"
> filePattern="${log-path}/myexample-%d{yyyy-MM-dd}.log" >
> it will create "myexample.log" and write on that until date changed. after
> date changed then, it moved to "myexample.2015-07-31.log" with pattern.
>
> but I want to create appending log file with every day's date patterned.
> myexample.2015-07-31.log
> myexample.2015-08-01.log
>
> "myexample.log" should not exist.
>
> this not working.
> <RollingFile name="RollingFile"
> fileName="${log-path}/myexample-%d{yyyy-MM-dd}.log"
> filePattern="${log-path}/myexample-%d{yyyy-MM-dd}.log" >
> this will create file "myexample-%{yyyy-MM-dd}.log" not
> "myexample-205-07-31"
>
> I hope you can understand me.
>
>
> similar post.
> http://stackoverflow.com/a/8888867
>
> thanks.
>
> 2015-07-31 10:11 GMT+09:00 Gary Gregory <ga...@gmail.com>:
>
>> Hun,
>>
>> Please see
>>
>> https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingRandomAccessFileAppender
>>
>> Gary
>>
>> On Thu, Jul 30, 2015 at 5:26 PM, no jihun <je...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> I want log4j to write at file which current date postfixed.
>>>
>>> for example, if today is 2015-07-31
>>> - expected file name created : logs/test.log.2015-07-31
>>> - (not this one : logs/test.log)
>>>
>>> when I use log4j I could do that by following.
>>> <appender name="testLog"
>>> class="org.apache.log4j.rolling.RollingFileAppender">
>>> <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
>>> <param name="FileNamePattern" value="/home/logs/test.log.%d{yyyy-MM-dd}"
>> />
>>> </rollingPolicy>
>>> <layout class="org.apache.log4j.PatternLayout">
>>> <param name="ConversionPattern" value="%m%n" />
>>> </layout>
>>> </appender>
>>>
>>> TimeBasedRollingPolicy is class in apache-log4j-extras.jar
>>> This configuration make It's down dated log file at the beginning
>> of
>>> every new day.
>>>
>>>
>>> How can I do this with* log4j2*'s org.apache.logging.log4j.core.appender.
>>> RollingFileAppender?
>>>
>>> Thanks!
>>> Hun
>>>
>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> ----------------------------------------------
> Jihun No ( 노지훈 )
> ----------------------------------------------
> Twitter : @nozisim
> Facebook : nozisim
> Website : http://jeesim2.godohosting.com
> ---------------------------------------------------------------------------------
> Market Apps : android market products.
> <https://market.android.com/developer?pub=%EB%85%B8%EC%A7%80%ED%9B%88>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: Including current date postfix in fileName (log4j2)
Posted by no jihun <je...@gmail.com>.
thank you for your concern
but it seems like neither RollingFileAppender nor
RollingRandomAccessFileAppender
<https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingRandomAccessFileAppender>
could
not create currently appending file name with datePattern.
just create fileName and moved with rolling pattern.
with is configuration
<RollingFile name="RollingFile" fileName="${log-path}/myexample.log"
filePattern="${log-path}/myexample-%d{yyyy-MM-dd}.log" >
it will create "myexample.log" and write on that until date changed. after
date changed then, it moved to "myexample.2015-07-31.log" with pattern.
but I want to create appending log file with every day's date patterned.
myexample.2015-07-31.log
myexample.2015-08-01.log
"myexample.log" should not exist.
this not working.
<RollingFile name="RollingFile"
fileName="${log-path}/myexample-%d{yyyy-MM-dd}.log"
filePattern="${log-path}/myexample-%d{yyyy-MM-dd}.log" >
this will create file "myexample-%{yyyy-MM-dd}.log" not
"myexample-205-07-31"
I hope you can understand me.
similar post.
http://stackoverflow.com/a/8888867
thanks.
2015-07-31 10:11 GMT+09:00 Gary Gregory <ga...@gmail.com>:
> Hun,
>
> Please see
>
> https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingRandomAccessFileAppender
>
> Gary
>
> On Thu, Jul 30, 2015 at 5:26 PM, no jihun <je...@gmail.com> wrote:
>
> > Hello,
> >
> > I want log4j to write at file which current date postfixed.
> >
> > for example, if today is 2015-07-31
> > - expected file name created : logs/test.log.2015-07-31
> > - (not this one : logs/test.log)
> >
> > when I use log4j I could do that by following.
> > <appender name="testLog"
> > class="org.apache.log4j.rolling.RollingFileAppender">
> > <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
> > <param name="FileNamePattern" value="/home/logs/test.log.%d{yyyy-MM-dd}"
> />
> > </rollingPolicy>
> > <layout class="org.apache.log4j.PatternLayout">
> > <param name="ConversionPattern" value="%m%n" />
> > </layout>
> > </appender>
> >
> > TimeBasedRollingPolicy is class in apache-log4j-extras.jar
> > This configuration make It's down dated log file at the beginning
> of
> > every new day.
> >
> >
> > How can I do this with* log4j2*'s org.apache.logging.log4j.core.appender.
> > RollingFileAppender?
> >
> > Thanks!
> > Hun
> >
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
--
----------------------------------------------
Jihun No ( 노지훈 )
----------------------------------------------
Twitter : @nozisim
Facebook : nozisim
Website : http://jeesim2.godohosting.com
---------------------------------------------------------------------------------
Market Apps : android market products.
<https://market.android.com/developer?pub=%EB%85%B8%EC%A7%80%ED%9B%88>
Re: Including current date postfix in fileName (log4j2)
Posted by Gary Gregory <ga...@gmail.com>.
Hun,
Please see
https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingRandomAccessFileAppender
Gary
On Thu, Jul 30, 2015 at 5:26 PM, no jihun <je...@gmail.com> wrote:
> Hello,
>
> I want log4j to write at file which current date postfixed.
>
> for example, if today is 2015-07-31
> - expected file name created : logs/test.log.2015-07-31
> - (not this one : logs/test.log)
>
> when I use log4j I could do that by following.
> <appender name="testLog"
> class="org.apache.log4j.rolling.RollingFileAppender">
> <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
> <param name="FileNamePattern" value="/home/logs/test.log.%d{yyyy-MM-dd}" />
> </rollingPolicy>
> <layout class="org.apache.log4j.PatternLayout">
> <param name="ConversionPattern" value="%m%n" />
> </layout>
> </appender>
>
> TimeBasedRollingPolicy is class in apache-log4j-extras.jar
> This configuration make It's down dated log file at the beginning of
> every new day.
>
>
> How can I do this with* log4j2*'s org.apache.logging.log4j.core.appender.
> RollingFileAppender?
>
> Thanks!
> Hun
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory