logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James <x...@yahoo.com>
Subject DailyRollingAppender
Date Wed, 21 Apr 2004 21:38:17 GMT
Hi,

I created my appender similiar to DailyRollingAppender
and used in ejb. My appender use the datetime passed
from ejb in MDC and write to the file based on the
datetime, it's mainly used to deal with midnight
logging to previous day file. Recently it got screwed
up. I had a logging request at 00:00:01 and needs to
be written to previous day file, but the file only has
this line there, all the content are gone.
here is the code, anybody see why it happened:

public void activateOptions() {

    if(datePattern != null) {
      now.setTime(System.currentTimeMillis());
      sdf = new SimpleDateFormat(datePattern);
      scheduledFilename = fileName = sdf.format(now);
    } else {
      System.out.println("=== DatePattern option are
not set for ["+ name+"] ===.");
    }
    super.activateOptions();
  }

  void rollover() throws IOException {

    String datedFileName = sdf.format(now);

    if (scheduledFilename.equals(datedFileName))
      return;

    // close current file
    this.closeFile();

    try {
      // This will also close the file. This is OK
since multiple
      // close operations are safe.
      this.setFile(datedFileName, false,
this.bufferedIO, this.bufferSize);
    }
    catch(IOException e) {
      System.out.println(this.getClass().getName()+
"setFile("+fileName+", false) call failed.");
      throw e;
    }
    scheduledFilename = fileName =  datedFileName;
  }

  protected void subAppend(LoggingEvent event) {

    String timeStamp = (String)LogWrapper.get("time");
    now.setTime(System.currentTimeMillis());
    if(timeStamp != null) {
      try{
        SimpleDateFormat df = new
SimpleDateFormat("MM-dd-yyyy");
        Date d = df.parse(timeStamp);
        long n = d.getTime();
        now.setTime(n);
      } catch(ParseException e) {
        //invalid time, use current time
        System.out.println(this.getClass().getName()+
"Invalid transactionTime. Use current time." + e);
      }
    }

    try{
      rollover();
    }catch (Exception e){
      e.printStackTrace();
      System.out.println(this.getClass().getName()+
"Unable to append. " + e);
    }
    super.subAppend(event);
  }


	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25
http://photos.yahoo.com/ph/print_splash

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


Mime
View raw message