EventRecodingLogger xref

View Javadoc

    1   package org.slf4j.event;
    2
    3   import java.util.Queue;
    4
    5   import org.slf4j.Logger;
    6   import org.slf4j.Marker;
    7   import org.slf4j.helpers.SubstituteLogger;
    8
    9   public class EventRecodingLogger implements Logger {
    10
    11      String name;
    12      SubstituteLogger logger;
    13      Queue<SubstituteLoggingEvent> eventQueue;
    14
    15      public EventRecodingLogger(SubstituteLogger logger, Queue<SubstituteLoggingEvent> eventQueue) {
    16          this.logger = logger;
    17          this.name = logger.getName();
    18          this.eventQueue = eventQueue;
    19      }
    20
    21      public String getName() {
    22          return name;
    23      }
    24
    25      private void recordEvent(Level level, String msg, Object[] args, Throwable throwable) {
    26          recordEvent(level, null, msg, args, throwable);
    27      }
    28
    29      private void recordEvent(Level level, Marker marker, String msg, Object[] args, Throwable throwable) {
    30          // System.out.println("recording logger:"+name+", msg:"+msg);
    31          SubstituteLoggingEvent loggingEvent = new SubstituteLoggingEvent();
    32          loggingEvent.setTimeStamp(System.currentTimeMillis());
    33          loggingEvent.setLevel(level);
    34          loggingEvent.setLogger(logger);
    35          loggingEvent.setLoggerName(name);
    36          loggingEvent.setMarker(marker);
    37          loggingEvent.setMessage(msg);
    38          loggingEvent.setArgumentArray(args);
    39          loggingEvent.setThrowable(throwable);
    40          loggingEvent.setThreadName(Thread.currentThread().getName());
    41          eventQueue.add(loggingEvent);
    42      }
    43
    44      public boolean isTraceEnabled() {
    45          return true;
    46      }
    47
    48      public void trace(String msg) {
    49          recordEvent(Level.TRACE, msg, null, null);
    50      }
    51
    52      public void trace(String format, Object arg) {
    53          recordEvent(Level.TRACE, format, new Object[] { arg }, null);
    54      }
    55
    56      public void trace(String format, Object arg1, Object arg2) {
    57          recordEvent(Level.TRACE, format, new Object[] { arg1, arg2 }, null);
    58      }
    59
    60      public void trace(String format, Object... arguments) {
    61          recordEvent(Level.TRACE, format, arguments, null);
    62      }
    63
    64      public void trace(String msg, Throwable t) {
    65          recordEvent(Level.TRACE, msg, null, t);
    66      }
    67
    68      public boolean isTraceEnabled(Marker marker) {
    69          return true;
    70      }
    71
    72      public void trace(Marker marker, String msg) {
    73          recordEvent(Level.TRACE, marker, msg, null, null);
    74
    75      }
    76
    77      public void trace(Marker marker, String format, Object arg) {
    78          recordEvent(Level.TRACE, marker, format, new Object[] { arg }, null);
    79      }
    80
    81      public void trace(Marker marker, String format, Object arg1, Object arg2) {
    82          recordEvent(Level.TRACE, marker, format, new Object[] { arg1, arg2 }, null);
    83      }
    84
    85      public void trace(Marker marker, String format, Object... argArray) {
    86          recordEvent(Level.TRACE, marker, format, argArray, null);
    87
    88      }
    89
    90      public void trace(Marker marker, String msg, Throwable t) {
    91          recordEvent(Level.TRACE, marker, msg, null, t);
    92      }
    93
    94      public boolean isDebugEnabled() {
    95          return true;
    96      }
    97
    98      public void debug(String msg) {
    99          recordEvent(Level.TRACE, msg, null, null);
    100     }
    101
    102     public void debug(String format, Object arg) {
    103         recordEvent(Level.DEBUG, format, new Object[] { arg }, null);
    104
    105     }
    106
    107     public void debug(String format, Object arg1, Object arg2) {
    108         recordEvent(Level.DEBUG, format, new Object[] { arg1, arg2 }, null);
    109
    110     }
    111
    112     public void debug(String format, Object... arguments) {
    113         recordEvent(Level.DEBUG, format, arguments, null);
    114     }
    115
    116     public void debug(String msg, Throwable t) {
    117         recordEvent(Level.DEBUG, msg, null, t);
    118     }
    119
    120     public boolean isDebugEnabled(Marker marker) {
    121         return true;
    122     }
    123
    124     public void debug(Marker marker, String msg) {
    125         recordEvent(Level.DEBUG, marker, msg, null, null);
    126     }
    127
    128     public void debug(Marker marker, String format, Object arg) {
    129         recordEvent(Level.DEBUG, marker, format, new Object[] { arg }, null);
    130     }
    131
    132     public void debug(Marker marker, String format, Object arg1, Object arg2) {
    133         recordEvent(Level.DEBUG, marker, format, new Object[] { arg1, arg2 }, null);
    134     }
    135
    136     public void debug(Marker marker, String format, Object... arguments) {
    137         recordEvent(Level.DEBUG, marker, format, arguments, null);
    138     }
    139
    140     public void debug(Marker marker, String msg, Throwable t) {
    141         recordEvent(Level.DEBUG, marker, msg, null, t);
    142     }
    143
    144     public boolean isInfoEnabled() {
    145         return true;
    146     }
    147
    148     public void info(String msg) {
    149         recordEvent(Level.INFO, msg, null, null);
    150     }
    151
    152     public void info(String format, Object arg) {
    153         recordEvent(Level.INFO, format, new Object[] { arg }, null);
    154     }
    155
    156     public void info(String format, Object arg1, Object arg2) {
    157         recordEvent(Level.INFO, format, new Object[] { arg1, arg2 }, null);
    158     }
    159
    160     public void info(String format, Object... arguments) {
    161         recordEvent(Level.INFO, format, arguments, null);
    162     }
    163
    164     public void info(String msg, Throwable t) {
    165         recordEvent(Level.INFO, msg, null, t);
    166     }
    167
    168     public boolean isInfoEnabled(Marker marker) {
    169         return true;
    170     }
    171
    172     public void info(Marker marker, String msg) {
    173         recordEvent(Level.INFO, marker, msg, null, null);
    174     }
    175
    176     public void info(Marker marker, String format, Object arg) {
    177         recordEvent(Level.INFO, marker, format, new Object[] { arg }, null);
    178     }
    179
    180     public void info(Marker marker, String format, Object arg1, Object arg2) {
    181         recordEvent(Level.INFO, marker, format, new Object[] { arg1, arg2 }, null);
    182     }
    183
    184     public void info(Marker marker, String format, Object... arguments) {
    185         recordEvent(Level.INFO, marker, format, arguments, null);
    186     }
    187
    188     public void info(Marker marker, String msg, Throwable t) {
    189         recordEvent(Level.INFO, marker, msg, null, t);
    190
    191     }
    192
    193     public boolean isWarnEnabled() {
    194         return true;
    195     }
    196
    197     public void warn(String msg) {
    198         recordEvent(Level.WARN, msg, null, null);
    199     }
    200
    201     public void warn(String format, Object arg) {
    202         recordEvent(Level.WARN, format, new Object[] { arg }, null);
    203
    204     }
    205
    206     public void warn(String format, Object arg1, Object arg2) {
    207         recordEvent(Level.WARN, format, new Object[] { arg1, arg2 }, null);
    208     }
    209
    210     public void warn(String format, Object... arguments) {
    211         recordEvent(Level.WARN, format, arguments, null);
    212     }
    213
    214     public void warn(String msg, Throwable t) {
    215         recordEvent(Level.WARN, msg, null, t);
    216     }
    217
    218     public boolean isWarnEnabled(Marker marker) {
    219         return true;
    220     }
    221
    222     public void warn(Marker marker, String msg) {
    223         recordEvent(Level.WARN, msg, null, null);
    224     }
    225
    226     public void warn(Marker marker, String format, Object arg) {
    227         recordEvent(Level.WARN, format, new Object[] { arg }, null);
    228     }
    229
    230     public void warn(Marker marker, String format, Object arg1, Object arg2) {
    231         recordEvent(Level.WARN, marker, format, new Object[] { arg1, arg2 }, null);
    232
    233     }
    234
    235     public void warn(Marker marker, String format, Object... arguments) {
    236         recordEvent(Level.WARN, marker, format, arguments, null);
    237     }
    238
    239     public void warn(Marker marker, String msg, Throwable t) {
    240         recordEvent(Level.WARN, marker, msg, null, t);
    241     }
    242
    243     public boolean isErrorEnabled() {
    244         return true;
    245     }
    246
    247     public void error(String msg) {
    248         recordEvent(Level.ERROR, msg, null, null);
    249     }
    250
    251     public void error(String format, Object arg) {
    252         recordEvent(Level.ERROR, format, new Object[] { arg }, null);
    253
    254     }
    255
    256     public void error(String format, Object arg1, Object arg2) {
    257         recordEvent(Level.ERROR, format, new Object[] { arg1, arg2 }, null);
    258
    259     }
    260
    261     public void error(String format, Object... arguments) {
    262         recordEvent(Level.ERROR, format, arguments, null);
    263
    264     }
    265
    266     public void error(String msg, Throwable t) {
    267         recordEvent(Level.ERROR, msg, null, t);
    268     }
    269
    270     public boolean isErrorEnabled(Marker marker) {
    271         return true;
    272     }
    273
    274     public void error(Marker marker, String msg) {
    275         recordEvent(Level.ERROR, marker, msg, null, null);
    276
    277     }
    278
    279     public void error(Marker marker, String format, Object arg) {
    280         recordEvent(Level.ERROR, marker, format, new Object[] { arg }, null);
    281
    282     }
    283
    284     public void error(Marker marker, String format, Object arg1, Object arg2) {
    285         recordEvent(Level.ERROR, marker, format, new Object[] { arg1, arg2 }, null);
    286     }
    287
    288     public void error(Marker marker, String format, Object... arguments) {
    289         recordEvent(Level.ERROR, marker, format, arguments, null);
    290     }
    291
    292     public void error(Marker marker, String msg, Throwable t) {
    293         recordEvent(Level.ERROR, marker, msg, null, t);
    294     }
    295
    296 }