Maybe it's too trival, but I definitely need some
help.
Thanks
--- James <[EMAIL PROTECTED]> wrote:
> 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:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]