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 "Bohdan Mushkevych (JIRA)" <ji...@apache.org> on 2014/03/24 18:40:48 UTC

[jira] [Comment Edited] (LOG4J2-550) .log files are left un-archived after JVM restart

    [ https://issues.apache.org/jira/browse/LOG4J2-550?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13945401#comment-13945401 ] 

Bohdan Mushkevych edited comment on LOG4J2-550 at 3/24/14 5:40 PM:
-------------------------------------------------------------------

I believe this issue is caused by overlapping of two factors:
- all .log file names are dynamic (driven by ${sd::type} value)
Hence - log4j2 could not track them explicitly, and when the JVM is restarted - old .log files are left unaccounted.
- using ${date:yyyyMMdd} in the filename pattern
In contrary to %d{yyyyMMdd} it seams to be static and computed only once - at the JVM startup

To address both issues I came up with the following .xml file:

{code:xml}
    <Properties>
        <Property name="routing_filename">${log.path}/table-$${sd:type}.log</Property>
    </Properties>

     <Routing name="Routing">
            <Routes pattern="$${sd:type}">
                <Route>
                    <RollingFile name="RollingFile-${sd:type}"
                                 fileName="${routing_filename}"
                                 filePattern="${log.path}/%d{yyyyMMdd}/%d{yyyyMMddHH}-${sd:type}-${hostName}.%i.log.gz">
                        <PatternLayout>
                            <!-- %K{v} stands for the message passed in StructuredDataMessage map with key "v" -->
                            <!-- %n stands for new line -->
                            <Pattern>%d{yyyyMMddHH},%K{v}%n</Pattern>
                        </PatternLayout>
                        <Policies>
                            <TimeBasedTriggeringPolicy interval="1"/>
                            <SizeBasedTriggeringPolicy size="64 MB"/>
                        </Policies>
                        <DefaultRolloverStrategy max="999"/>
                    </RollingFile>
                </Route>
            </Routes>
        </Routing>
{code}


was (Author: mushkevych):
I believe this issue is caused by overlapping of two factors:
- all .log file names are dynamic (driven by ${sd::type} value)
Hence - log4j2 could not track them explicitly, and when the JVM is restarted - old .log files are left unaccounted.
- using ${date:yyyyMMdd} in the filename pattern
In contrary to %d{yyyyMMdd} it seams to be static and computed only once - at the JVM startup

To address both issues I came up with the following .xml file:
    <Properties>
        <Property name="routing_filename">${log.path}/table-$${sd:type}.log</Property>
    </Properties>

     <Routing name="Routing">
            <Routes pattern="$${sd:type}">
                <Route>
                    <RollingFile name="RollingFile-${sd:type}"
                                 fileName="${routing_filename}"
                                 filePattern="${log.path}/%d{yyyyMMdd}/%d{yyyyMMddHH}-${sd:type}-${hostName}.%i.log.gz">
                        <PatternLayout>
                            <!-- %K{v} stands for the message passed in StructuredDataMessage map with key "v" -->
                            <!-- %n stands for new line -->
                            <Pattern>%d{yyyyMMddHH},%K{v}%n</Pattern>
                        </PatternLayout>
                        <Policies>
                            <TimeBasedTriggeringPolicy interval="1"/>
                            <SizeBasedTriggeringPolicy size="64 MB"/>
                        </Policies>
                        <DefaultRolloverStrategy max="999"/>
                    </RollingFile>
                </Route>
            </Routes>
        </Routing>


> .log files are left un-archived after JVM restart
> -------------------------------------------------
>
>                 Key: LOG4J2-550
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-550
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0-rc1
>            Reporter: Bohdan Mushkevych
>         Attachments: log4j2.xml
>
>
> I am using log4j 2.0-rc1, StructuredDataMessage and EventLogger to perform dynamic logging.
> Attached log4j2.xml configuration meant to:
> - rotate log files on hourly basis OR after file reaches 64 MB (whatever comes first)
> - archive logs that does not satisfy the file pattern
> Whenever JVM is restarted, log4j abandons "old" files un-archived:
> -rw-r--r--. 1 root root   317625 Feb 24 20:16 2014022419-sim-mdmlocal.mobidia.com.log
> -rw-r--r--. 1 root root  3333648 Feb 24 20:20 2014022420-activity-mdmlocal.mobidia.com.log
> Listing above shows that file 2014022419-sim-mdmlocal.mobidia.com.log was last touched by the system at 20:16, and should have been archived to .log.gz after restart, which occurred soon after



--
This message was sent by Atlassian JIRA
(v6.2#6252)

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