You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Remko Popma (JIRA)" <ji...@apache.org> on 2015/09/03 08:52:45 UTC

[jira] [Updated] (LOG4J2-1101) Date based file appender

     [ https://issues.apache.org/jira/browse/LOG4J2-1101?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma updated LOG4J2-1101:
--------------------------------
    Description: 
I'd like to reintroduce the option of logging to a file that has the current date in it. 

For example, when the app starts up, it will start logging to myapp-20150821.log. At midnight, it starts logging to a new file named myapp-20150822.log.

Log4j2's RollingFileAppender does not support this. In log4j2 the file appender will log to one file with a static file name, and then the content is moved over to another file. 

This used to be a feature in log4j 1.3, when using extras. I would configure it like this:
{code}
    <appender name="myapp" class="org.apache.log4j.rolling.RollingFileAppender">
        <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="FileNamePattern" value="myapp-%d{yyyyMMdd}.log"/>
        </rollingPolicy>
        ....
    </appender>
{code}

The only way I found that it would work in log4j2 is to use the following code, but that's pretty hacky:
https://gist.github.com/tomaszalusky/b9109c0faddafe099835


  was:
I'd like to reintroduce the option of logging to a file that has the current date in it. 

For example, when the app starts up, it will start logging to myapp-20150821.log. At midnight, it starts logging to a new file named myapp-20150822.log.

Log4j2's RollingFileAppender does not support this. In log4j2 the file appender will log to one file with a static file name, and then the content is moved over to another file. 

This used to be a feature in log4j 1.3, when using extras. I would configure it like this:
    <appender name="myapp" class="org.apache.log4j.rolling.RollingFileAppender">
        <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="FileNamePattern" value="myapp-%d{yyyyMMdd}.log"/>
        </rollingPolicy>
        ....
    </appender>

The only way I found that it would work in log4j2 is to use the following code, but that's pretty hacky:
https://gist.github.com/tomaszalusky/b9109c0faddafe099835



> Date based file appender
> ------------------------
>
>                 Key: LOG4J2-1101
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1101
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: Appenders
>            Reporter: Haavar Valeur
>
> I'd like to reintroduce the option of logging to a file that has the current date in it. 
> For example, when the app starts up, it will start logging to myapp-20150821.log. At midnight, it starts logging to a new file named myapp-20150822.log.
> Log4j2's RollingFileAppender does not support this. In log4j2 the file appender will log to one file with a static file name, and then the content is moved over to another file. 
> This used to be a feature in log4j 1.3, when using extras. I would configure it like this:
> {code}
>     <appender name="myapp" class="org.apache.log4j.rolling.RollingFileAppender">
>         <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
>             <param name="FileNamePattern" value="myapp-%d{yyyyMMdd}.log"/>
>         </rollingPolicy>
>         ....
>     </appender>
> {code}
> The only way I found that it would work in log4j2 is to use the following code, but that's pretty hacky:
> https://gist.github.com/tomaszalusky/b9109c0faddafe099835



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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