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 Baron Fujimoto <ba...@hawaii.edu> on 2016/10/28 02:37:27 UTC

confused by log4j2 Rolling File Appender

I'm trying to configure I'm trying to configure an application (Apereo's CAS 5)
to roll its log files daily. This is an excerpt from its log4j2.xml config file
based on the the log4j2 documentation here

<https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingFileAppender>

    <RollingFile name="file" fileName="/path/to/cas/logs/cas.log" append="true"
                 filePattern="/path/to/cas/logs/cas.log.%d{yyyy-MM-dd}">
        <PatternLayout pattern="%d %p [%c] - &lt;%m&gt;%n"/>
        <Policies>
            <OnStartupTriggeringPolicy />
            <SizeBasedTriggeringPolicy />
            <TimeBasedTriggeringPolicy interval="1" modulate="true" />
        </Policies>
    </RollingFile>

But when CAS starts up, I see the following:

2016-10-27 17:32:02,461 localhost-startStop-1 ERROR Unable to move file /path/to/cas/logs/cas.log.2016-10-27 to /path/to/cas/logs/cas.log.2016-10-27: java.nio.file.NoSuchFile Exception /path/to/cas/logs/cas.log.2016-10-27 -> /path/to/cas/logs/cas.log.2016-10-27
2016-10-27 17:32:02,464 localhost-startStop-1 ERROR Unable to copy file /path/to/cas/logs/cas.log.2016-10-27 to /path/to/cas/logs/cas.log.2016-10-27: java.nio.file.NoSuchFile Exception /path/to/cas/logs/cas.log.2016-10-27

I don't understand

1) why it's trying to move (and copy?) cas.log.2016-10-10 to
cas.log.2016-10-10

2) why the NoSuchFileException when
$ ls -go /path/to/cas/logs/cas.log.2016-10-10
-rw-r--r--. 1 641647 Oct 27 17:32 /path/to/cas/logs/cas.log.2016-10-27

If I don't touch things, it seems to mostly roll the logs daily, but if
I stop and restart the Tomcat container for the app, it appears to roll
the logfile on restart, and discard or overwrite any previous log that
may have been rolled the same day.

Any ideas as to what I'm doing wrong or suggestions onhow to fix this
would be appreciated.

Aloha,
-baron
-- 
Baron Fujimoto <ba...@hawaii.edu> :: UH Information Technology Services
minutas cantorum, minutas balorum, minutas carboratum desendus pantorum

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


Re: confused by log4j2 Rolling File Appender

Posted by "Tungathurthi, Chandra Kiran Bharadwaj" <ch...@rwth-aachen.de>.
Baron, the issue seemed to be in the filepattern. Usually, this is used for archiving while rolling. 

from [https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingFileAppender]: 

filePattern:	The pattern of the file name of the archived log file. The format of the pattern is dependent on the RolloverPolicy that is used. The DefaultRolloverPolicy will accept both a date/time pattern compatible with SimpleDateFormat and/or a %i which represents an integer counter. The pattern also supports interpolation at runtime so any of the Lookups (such as the DateLookup) can be included in the pattern.


>>discard or overwrite any previous log that may have been rolled the same day.
You need use the file index %i to roll onto a different file else the same file will be overwritten.   

try this : path/to/cas/logs/cas.log_%d{MM-dd-yyyy}-%i.log.gz


----
Thanks & regards,
Chandra Tungathurthi


________________________________________
From: Baron Fujimoto <ba...@hawaii.edu>
Sent: Friday, October 28, 2016 04:37
To: log4j-user@logging.apache.org
Subject: confused by log4j2 Rolling File Appender

I'm trying to configure I'm trying to configure an application (Apereo's CAS 5)
to roll its log files daily. This is an excerpt from its log4j2.xml config file
based on the the log4j2 documentation here

<https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingFileAppender>

    <RollingFile name="file" fileName="/path/to/cas/logs/cas.log" append="true"
                 filePattern="/path/to/cas/logs/cas.log.%d{yyyy-MM-dd}">
        <PatternLayout pattern="%d %p [%c] - &lt;%m&gt;%n"/>
        <Policies>
            <OnStartupTriggeringPolicy />
            <SizeBasedTriggeringPolicy />
            <TimeBasedTriggeringPolicy interval="1" modulate="true" />
        </Policies>
    </RollingFile>

But when CAS starts up, I see the following:

2016-10-27 17:32:02,461 localhost-startStop-1 ERROR Unable to move file /path/to/cas/logs/cas.log.2016-10-27 to /path/to/cas/logs/cas.log.2016-10-27: java.nio.file.NoSuchFile Exception /path/to/cas/logs/cas.log.2016-10-27 -> /path/to/cas/logs/cas.log.2016-10-27
2016-10-27 17:32:02,464 localhost-startStop-1 ERROR Unable to copy file /path/to/cas/logs/cas.log.2016-10-27 to /path/to/cas/logs/cas.log.2016-10-27: java.nio.file.NoSuchFile Exception /path/to/cas/logs/cas.log.2016-10-27

I don't understand

1) why it's trying to move (and copy?) cas.log.2016-10-10 to
cas.log.2016-10-10

2) why the NoSuchFileException when
$ ls -go /path/to/cas/logs/cas.log.2016-10-10
-rw-r--r--. 1 641647 Oct 27 17:32 /path/to/cas/logs/cas.log.2016-10-27

If I don't touch things, it seems to mostly roll the logs daily, but if
I stop and restart the Tomcat container for the app, it appears to roll
the logfile on restart, and discard or overwrite any previous log that
may have been rolled the same day.

Any ideas as to what I'm doing wrong or suggestions onhow to fix this
would be appreciated.

Aloha,
-baron
--
Baron Fujimoto <ba...@hawaii.edu> :: UH Information Technology Services
minutas cantorum, minutas balorum, minutas carboratum desendus pantorum

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


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