View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.classic.pattern;
11  
12  import ch.qos.logback.classic.spi.LoggingEvent;
13  
14  public class RelativeTimeConverter extends ClassicConverter {
15  
16    long lastTimestamp = -1;
17    String timesmapStr = null;
18    
19    public String convert(LoggingEvent event) {
20      long timestamp = event.getTimeStamp();
21      
22      // if called multiple times within the same millisecond
23      // return old value
24      if(timestamp == lastTimestamp) {
25        return timesmapStr;
26      } else {
27        lastTimestamp = timestamp;
28        timesmapStr = Long.toString(timestamp - LoggingEvent.getStartTime());
29        return timesmapStr;
30      }
31    }
32  }