logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Help understanding StatusLogger
Date Fri, 28 Sep 2012 18:04:11 GMT
Hi All:

Consider what happens when no one listens to a
org.apache.logging.log4j.status.StatusLogger in log(Marker, String, Level,
Message, Throwable):

    /**
     * Add an event.
     * @param marker The Marker
     * @param fqcn   The fully qualified class name of the <b>caller</b>
     * @param level  The logging level
     * @param msg    The message associated with the event.
     * @param t      A Throwable or null.
     */
    @Override
    public void log(Marker marker, String fqcn, Level level, Message msg,
Throwable t) {
        StackTraceElement element = null;
        if (fqcn != null) {
            element = getStackTraceElement(fqcn,
Thread.currentThread().getStackTrace());
        }
        StatusData data = new StatusData(element, level, msg, t);
        msgLock.lock();
        try {
            messages.add(data);
        } finally {
            msgLock.unlock();
        }
        for (StatusListener listener : listeners) {
            listener.log(data);
        }
    }

Code runs in the methods, creating objects and so on only to have:

        for (StatusListener listener : listeners) {
            listener.log(data);
        }


do nothing. But before that, the method records a data object in the messages
queue.

Why? It does not seem that references are used ATM.

If thought the method could be guarded by this at the top:

        if (listeners.isEmpty()) {
            return;
        }

But then the behavior would be different since the data object would not be
queued.

Please help me understand.

Thank you!

Gary
-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
View raw message