View Javadoc
1   package org.slf4j.event;
2   
3   import java.util.Queue;
4   
5   import org.slf4j.Marker;
6   import org.slf4j.helpers.LegacyAbstractLogger;
7   import org.slf4j.helpers.SubstituteLogger;
8   
9   /**
10   * 
11   * This class is used to record events during the initialization phase of the
12   * underlying logging framework. It is called by {@link SubstituteLogger}.
13   * 
14   * 
15   * @author Ceki Gülcü
16   * @author Wessel van Norel
17   *
18   */
19  public class EventRecordingLogger extends LegacyAbstractLogger {
20  
21      private static final long serialVersionUID = -176083308134819629L;
22  
23      String name;
24      SubstituteLogger logger;
25      Queue<SubstituteLoggingEvent> eventQueue;
26  
27      // as an event recording logger we have no choice but to record all events
28      final static boolean RECORD_ALL_EVENTS = true;
29  
30      public EventRecordingLogger(SubstituteLogger logger, Queue<SubstituteLoggingEvent> eventQueue) {
31          this.logger = logger;
32          this.name = logger.getName();
33          this.eventQueue = eventQueue;
34      }
35  
36      public String getName() {
37          return name;
38      }
39  
40      public boolean isTraceEnabled() {
41          return RECORD_ALL_EVENTS;
42      }
43  
44      public boolean isDebugEnabled() {
45          return RECORD_ALL_EVENTS;
46      }
47  
48      public boolean isInfoEnabled() {
49          return RECORD_ALL_EVENTS;
50      }
51  
52      public boolean isWarnEnabled() {
53          return RECORD_ALL_EVENTS;
54      }
55  
56      public boolean isErrorEnabled() {
57          return RECORD_ALL_EVENTS;
58      }
59  
60      // WARNING: this method assumes that any throwable is properly extracted
61      protected void handleNormalizedLoggingCall(Level level, Marker marker, String msg, Object[] args, Throwable throwable) {
62          SubstituteLoggingEvent loggingEvent = new SubstituteLoggingEvent();
63          loggingEvent.setTimeStamp(System.currentTimeMillis());
64          loggingEvent.setLevel(level);
65          loggingEvent.setLogger(logger);
66          loggingEvent.setLoggerName(name);
67          if (marker != null) {
68              loggingEvent.addMarker(marker);
69          }
70          loggingEvent.setMessage(msg);
71          loggingEvent.setThreadName(Thread.currentThread().getName());
72  
73          loggingEvent.setArgumentArray(args);
74          loggingEvent.setThrowable(throwable);
75  
76          eventQueue.add(loggingEvent);
77  
78      }
79  
80      @Override
81      protected String getFullyQualifiedCallerName() {
82          return null;
83      }
84  }