001package org.slf4j.event; 002 003import java.util.Queue; 004 005import org.slf4j.Marker; 006import org.slf4j.helpers.LegacyAbstractLogger; 007import org.slf4j.helpers.SubstituteLogger; 008 009/** 010 * 011 * This class is used to record events during the initialization phase of the 012 * underlying logging framework. It is called by {@link SubstituteLogger}. 013 * 014 * 015 * @author Ceki Gülcü 016 * @author Wessel van Norel 017 * 018 */ 019public class EventRecordingLogger extends LegacyAbstractLogger { 020 021 private static final long serialVersionUID = -176083308134819629L; 022 023 String name; 024 SubstituteLogger logger; 025 Queue<SubstituteLoggingEvent> eventQueue; 026 027 // as an event recording logger we have no choice but to record all events 028 final static boolean RECORD_ALL_EVENTS = true; 029 030 public EventRecordingLogger(SubstituteLogger logger, Queue<SubstituteLoggingEvent> eventQueue) { 031 this.logger = logger; 032 this.name = logger.getName(); 033 this.eventQueue = eventQueue; 034 } 035 036 public String getName() { 037 return name; 038 } 039 040 public boolean isTraceEnabled() { 041 return RECORD_ALL_EVENTS; 042 } 043 044 public boolean isDebugEnabled() { 045 return RECORD_ALL_EVENTS; 046 } 047 048 public boolean isInfoEnabled() { 049 return RECORD_ALL_EVENTS; 050 } 051 052 public boolean isWarnEnabled() { 053 return RECORD_ALL_EVENTS; 054 } 055 056 public boolean isErrorEnabled() { 057 return RECORD_ALL_EVENTS; 058 } 059 060 // WARNING: this method assumes that any throwable is properly extracted 061 protected void handleNormalizedLoggingCall(Level level, Marker marker, String msg, Object[] args, Throwable throwable) { 062 SubstituteLoggingEvent loggingEvent = new SubstituteLoggingEvent(); 063 loggingEvent.setTimeStamp(System.currentTimeMillis()); 064 loggingEvent.setLevel(level); 065 loggingEvent.setLogger(logger); 066 loggingEvent.setLoggerName(name); 067 if (marker != null) { 068 loggingEvent.addMarker(marker); 069 } 070 loggingEvent.setMessage(msg); 071 loggingEvent.setThreadName(Thread.currentThread().getName()); 072 073 loggingEvent.setArgumentArray(args); 074 loggingEvent.setThrowable(throwable); 075 076 eventQueue.add(loggingEvent); 077 078 } 079 080 @Override 081 protected String getFullyQualifiedCallerName() { 082 return null; 083 } 084}