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

Remko Popma updated LOG4J2-1592:
--------------------------------
    Description: 
I am using the following config

{code}
<Configuration status="warn" name="in.transerv" packages="">
  <Properties>
    <Property name="baseDir">/var/log/tomcat</Property>
  </Properties>
  <Appenders>
    <RollingFile name="RollingFile" fileName="${baseDir}/app.log"
          filePattern="${baseDir}/$${date:yyyy-MM}/app-%d{yyyy-MM-dd}.log.gz">
      <PatternLayout pattern="%5p %d{ISO8601} [%t][%x] %c - %m%n" />
      <TimeBasedTriggeringPolicy/>
    </RollingFile>
  </Appenders>
  <Loggers>
    <Root level="debug">
      <AppenderRef ref="RollingFile"/>
    </Root>
</Configuration>
{code}

In my Tomcat startup, I have specified the log4j.xml file as 
-Dlog4j.configurationFile=<path to file>

It gets initialized properly as I see the logs coming in the app.log

However, at midnight of each day when it is supposed to rollover, I see the 
following directory structure

{code}
drwxr-xr-x 2 root root       62 Sep 18 00:00 2016-09
-rw-r--r-- 1 root root        0 Sep 18 07:48 app.log-2016-09-18
-rw-r--r-- 1 root root   351893 Sep 18 07:58 app.log
{code}

The file for the previous day gets truncated to 0 bytes and the directory 
2016-09 contains NOTHING. 

I just want to log to app.log and each day, I want to save the previous days 
log file as a .gz with the date pattern. But it is not happening.

I was using log4j 1.x, I switched over to 2.x since I was having issues with 
log files getting corrupted (log lines disappearing) when multiple tomcat 
processes tried to write into the same file. 

Please help me since these logs are critical to our application. Thanks.

  was:
I am using the following config

<Configuration status="warn" name="in.transerv" packages="">
  <Properties>
    <Property name="baseDir">/var/log/tomcat</Property>
  </Properties>
  <Appenders>
    <RollingFile name="RollingFile" fileName="${baseDir}/app.log"
          filePattern="${baseDir}/$${date:yyyy-MM}/app-%d{yyyy-MM-dd}.log.gz">
      <PatternLayout pattern="%5p %d{ISO8601} [%t][%x] %c - %m%n" />
      <TimeBasedTriggeringPolicy/>
    </RollingFile>
  </Appenders>
  <Loggers>
    <Root level="debug">
      <AppenderRef ref="RollingFile"/>
    </Root>
</Configuration>

In my Tomcat startup, I have specified the log4j.xml file as 
-Dlog4j.configurationFile=<path to file>

It gets initialized properly as I see the logs coming in the app.log

However, at midnight of each day when it is supposed to rollover, I see the 
following directory structure

drwxr-xr-x 2 root root       62 Sep 18 00:00 2016-09
-rw-r--r-- 1 root root        0 Sep 18 07:48 app.log-2016-09-18
-rw-r--r-- 1 root root   351893 Sep 18 07:58 app.log

The file for the previous day gets truncated to 0 bytes and the directory 
2016-09 contains NOTHING. 

I just want to log to app.log and each day, I want to save the previous days 
log file as a .gz with the date pattern. But it is not happening.

I was using log4j 1.x, I switched over to 2.x since I was having issues with 
log files getting corrupted (log lines disappearing) when multiple tomcat 
processes tried to write into the same file. 

Please help me since these logs are critical to our application. Thanks.


Be careful: Log4j 2 can be configured to correctly handle multiple _web 
applications_ running on the same Tomcat instance to log to the same file, but 
separate _processes_ logging to the same file may give unexpected results.

* If you use the RandomAccessFile appender, the different appenders will have 
separate file pointers and will overwrite each other's output.
* File appenders use the stream API which may work.
* However, if you use a RollingFileAppender, a rollover in one process may 
cause the file handle of the other process to become invalid and it may lose 
all subsequent logging.

> Logging not working properly
> ----------------------------
>
>                 Key: LOG4J2-1592
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1592
>             Project: Log4j 2
>          Issue Type: Bug
>         Environment: Linux 3.10.0-229.20.1.el7.x86_64 #1 SMP Tue Nov 3 
> 19:10:07 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
>            Reporter: Farhad Tarapore
>
> I am using the following config
> {code}
> <Configuration status="warn" name="in.transerv" packages="">
>   <Properties>
>     <Property name="baseDir">/var/log/tomcat</Property>
>   </Properties>
>   <Appenders>
>     <RollingFile name="RollingFile" fileName="${baseDir}/app.log"
>           filePattern="${baseDir}/$${date:yyyy-MM}/app-%d{yyyy-MM-dd}.log.gz">
>       <PatternLayout pattern="%5p %d{ISO8601} [%t][%x] %c - %m%n" />
>       <TimeBasedTriggeringPolicy/>
>     </RollingFile>
>   </Appenders>
>   <Loggers>
>     <Root level="debug">
>       <AppenderRef ref="RollingFile"/>
>     </Root>
> </Configuration>
> {code}
> In my Tomcat startup, I have specified the log4j.xml file as 
> -Dlog4j.configurationFile=<path to file>
> It gets initialized properly as I see the logs coming in the app.log
> However, at midnight of each day when it is supposed to rollover, I see the 
> following directory structure
> {code}
> drwxr-xr-x 2 root root       62 Sep 18 00:00 2016-09
> -rw-r--r-- 1 root root        0 Sep 18 07:48 app.log-2016-09-18
> -rw-r--r-- 1 root root   351893 Sep 18 07:58 app.log
> {code}
> The file for the previous day gets truncated to 0 bytes and the directory 
> 2016-09 contains NOTHING. 
> I just want to log to app.log and each day, I want to save the previous days 
> log file as a .gz with the date pattern. But it is not happening.
> I was using log4j 1.x, I switched over to 2.x since I was having issues with 
> log files getting corrupted (log lines disappearing) when multiple tomcat 
> processes tried to write into the same file. 
> Please help me since these logs are critical to our application. Thanks.



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

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

Reply via email to