logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "VijayaKumar Guddeti (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1250) [2.5] CronTriggeringPolicy renaming behavior when midnight.
Date Tue, 26 Jul 2016 09:26:20 GMT

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

VijayaKumar Guddeti commented on LOG4J2-1250:
---------------------------------------------

sharing few more finding from the testing done yesterday(25th-07-2016), its strange to see
polymorphic behavior from CronTriggeringPolicy(CTP) with respect to environment.

log4j2.xml:
-------------------------------------------------------------------------------------------------------------------------------------------------------
 <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
  <Appenders>
      <RollingFile name="dotLog" fileName="logs/app.log" filePattern="rolled-log-files/app-%d{yyyy-MM-dd_HH-mm-ss-SSS}.log"
  append="true" bufferedIO="false">
      
     	 <PatternLayout><Pattern>%d %p %c{1.} [%t] %m%n</Pattern></PatternLayout>
      
	     <Policies>
			<CronTriggeringPolicy schedule="0 0 0 * * ?"  evaluateOnStartup="true"/>
		        <SizeBasedTriggeringPolicy size="10 KB"/>
		</Policies>
    </RollingFile>
              
     <RollingFile name="dotCsv" fileName="logs/app.csv" filePattern="rolled-log-files/app-%d{yyyy-MM-dd_HH-mm-ss-SSS}.csv"
append="true" bufferedIO="false">
      
      	<PatternLayout><Pattern>%d %p %c{1.} [%t] %m%n</Pattern></PatternLayout>
      
	     <Policies>
			<CronTriggeringPolicy schedule="0 0 0 * * ?"  evaluateOnStartup="true"/>
		       <SizeBasedTriggeringPolicy size="10 KB"/>
		</Policies>
    </RollingFile>
    
  </Appenders>

  <Loggers>
    <Root level="trace">
    <AppenderRef ref="dotLog"/>
      <AppenderRef ref="dotCsv"/>
    </Root>
  </Loggers>
</Configuration>
-------------------------------------------------------------------------------------------------------------------------------------------------------
Simple Java code snippet used in testing:
-------------------------------------------------------------------------------------------------------------------------------------------------------
    	Logger dotLog = LogManager.getLogger("dotLog");
    	Logger dotCsv = LogManager.getLogger("dotCsv");
    	try{
    		for(int i=1;i>0;i++){
    			if(i<5){
    				dotLog.trace("dotLog trace message");
    				dotLog.debug("dotLog debug message");
    				dotLog.info("dotLog info message");
    				dotLog.error("dotLog error message");

    				dotCsv.trace("dotCsv trace message");
    				dotCsv.debug("dotCsv debug message");
    				dotCsv.info("dotCsv info message");
    				dotCsv.error("dotCsv error message");
    	    	System.out.println(i + " I'm going into sleep for a second " + (i%5 == 0));
    			}
    	    	Thread.sleep(1000);
    		}
    	}catch(Exception e){
    		e.printStackTrace();
    	}
-------------------------------------------------------------------------------------------------------------------------------------------------------
   	
I executed above code snipped in a main method just before midnight of 25th-July-2016 in Windows7
OS machine, 

1. app-2016-07-26_00-00-00-055.log
2. app-2016-07-26_00-00-00-056.csv

The similar code executed in one of the linux box, resulted below rolled-over files.

1. app-2016-07-25_00-00-00-055.log
2. app-2016-07-26_00-00-00-056.csv   

Try to catch, in linux machine .log extension file rolled-over at midnight with previous day
date in the file name, but .csv extension file rolled-over with new day date in the file name.

Kindly share your thoughts, if you feel this is helpful.

Thank you.

> [2.5] CronTriggeringPolicy renaming behavior when midnight.
> -----------------------------------------------------------
>
>                 Key: LOG4J2-1250
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1250
>             Project: Log4j 2
>          Issue Type: Question
>          Components: Appenders
>    Affects Versions: 2.5
>            Reporter: lee yongjoong
>            Assignee: Ralph Goers
>             Fix For: 2.6.2
>
>
> Hi.
> I tried CrontriggeringPolicy(added 2.5) for save daily log files at midnight.
> My goal is, for example.
> if today is 2015/01/01, "http.log" <- active file.
> and when midnight, "http.log" will be renamed "http_20150101.log", and create new "http.log".
> But my problem is when midnight, "http.log" renamed "http_20150102.log"...
> I want to make that file's name "http_20150101.log" because that file has 2015/01/01's
log,
> Here's my configure xml.
> {code:xml}
> <Routing name="routing_file">
>   <Routes pattern="pattern1">
>     <Route key="http">
>       <RollingFile name="rolling_http" filename="${path}/http.log" filepattern="${path}/http_%d{yyyyMMdd}.log">
>         <PatternLayout pattern="http"/>
>         <CronTriggeringPolicy schedule="0 0 0 * * ?"/>
>       </RollingFile>
>     </Route>
>   </Routes>
> </Routing>
> {code}
> Please help me.
> Thanks for your help, I'm very appreciated it :D



--
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


Mime
View raw message