/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.opentable.logging;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.UnsynchronizedAppenderBase;

/**
 * Appender implementation that simply captures logged messages.
 * Useful for writing logging tests.
 */
public class CaptureAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {

    public final List<ILoggingEvent> captured = new CopyOnWriteArrayList<>();

    @Override
    protected void append(ILoggingEvent eventObject) {
        captured.add(eventObject);
    }

}

@@ -657,16 +657,74 @@
 yList;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 import c
@@ -1202,10 +1202,1184 @@
 %0A    %7D%0A%0A
+    /**%0A     * Capture the root logger.%0A     * @return an updating list of logged events%0A     */%0A    public static List%3CILoggingEvent%3E capture() %7B%0A        return capture(Logger.ROOT_LOGGER_NAME);%0A    %7D%0A%0A    /**%0A     * Capture a logger by string name.%0A     * @param loggerName the logger to capture%0A     * @return an updating list of logged events%0A     */%0A    public static List%3CILoggingEvent%3E capture(String loggerName) %7B%0A        return capture(LoggerFactory.getLogger(loggerName));%0A    %7D%0A%0A    /**%0A     * Capture a logger by Class.%0A     * @param loggerClass the class whose logs to capture%0A     * @return an updating list of logged events%0A     */%0A    public static List%3CILoggingEvent%3E capture(Class%3C?%3E loggerClass) %7B%0A        return capture(LoggerFactory.getLogger(loggerClass));%0A    %7D%0A%0A    /**%0A     * Capture a Logger.%0A     * @param logger the Logger to capture%0A     * @return an updating list of logged events%0A     */%0A    public static List%3CILoggingEvent%3E capture(Logger logger) %7B%0A        CaptureAppender capture = new CaptureAppender();%0A        ((ch.qos.logback.classic.Logger) logger).addAppender(capture);%0A        capture.start();%0A        return capture.captured;%0A    %7D%0A
 %7D%0A

add convenience 'capture' method