Source code

    001package org.slf4j.event;
    002
    003import java.util.Queue;
    004
    005import org.slf4j.Logger;
    006import org.slf4j.Marker;
    007import org.slf4j.helpers.SubstituteLogger;
    008
    009public class EventRecodingLogger implements Logger {
    010
    011    String name;
    012    SubstituteLogger logger;
    013    Queue<SubstituteLoggingEvent> eventQueue;
    014
    015    public EventRecodingLogger(SubstituteLogger logger, Queue<SubstituteLoggingEvent> eventQueue) {
    016        this.logger = logger;
    017        this.name = logger.getName();
    018        this.eventQueue = eventQueue;
    019    }
    020
    021    public String getName() {
    022        return name;
    023    }
    024
    025    private void recordEvent(Level level, String msg, Object[] args, Throwable throwable) {
    026        recordEvent(level, null, msg, args, throwable);
    027    }
    028
    029    private void recordEvent(Level level, Marker marker, String msg, Object[] args, Throwable throwable) {
    030        // System.out.println("recording logger:"+name+", msg:"+msg);
    031        SubstituteLoggingEvent loggingEvent = new SubstituteLoggingEvent();
    032        loggingEvent.setTimeStamp(System.currentTimeMillis());
    033        loggingEvent.setLevel(level);
    034        loggingEvent.setLogger(logger);
    035        loggingEvent.setLoggerName(name);
    036        loggingEvent.setMarker(marker);
    037        loggingEvent.setMessage(msg);
    038        loggingEvent.setArgumentArray(args);
    039        loggingEvent.setThrowable(throwable);
    040        loggingEvent.setThreadName(Thread.currentThread().getName());
    041        eventQueue.add(loggingEvent);
    042    }
    043
    044    public boolean isTraceEnabled() {
    045        return true;
    046    }
    047
    048    public void trace(String msg) {
    049        recordEvent(Level.TRACE, msg, null, null);
    050    }
    051
    052    public void trace(String format, Object arg) {
    053        recordEvent(Level.TRACE, format, new Object[] { arg }, null);
    054    }
    055
    056    public void trace(String format, Object arg1, Object arg2) {
    057        recordEvent(Level.TRACE, format, new Object[] { arg1, arg2 }, null);
    058    }
    059
    060    public void trace(String format, Object... arguments) {
    061        recordEvent(Level.TRACE, format, arguments, null);
    062    }
    063
    064    public void trace(String msg, Throwable t) {
    065        recordEvent(Level.TRACE, msg, null, t);
    066    }
    067
    068    public boolean isTraceEnabled(Marker marker) {
    069        return true;
    070    }
    071
    072    public void trace(Marker marker, String msg) {
    073        recordEvent(Level.TRACE, marker, msg, null, null);
    074
    075    }
    076
    077    public void trace(Marker marker, String format, Object arg) {
    078        recordEvent(Level.TRACE, marker, format, new Object[] { arg }, null);
    079    }
    080
    081    public void trace(Marker marker, String format, Object arg1, Object arg2) {
    082        recordEvent(Level.TRACE, marker, format, new Object[] { arg1, arg2 }, null);
    083    }
    084
    085    public void trace(Marker marker, String format, Object... argArray) {
    086        recordEvent(Level.TRACE, marker, format, argArray, null);
    087
    088    }
    089
    090    public void trace(Marker marker, String msg, Throwable t) {
    091        recordEvent(Level.TRACE, marker, msg, null, t);
    092    }
    093
    094    public boolean isDebugEnabled() {
    095        return true;
    096    }
    097
    098    public void debug(String msg) {
    099        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}