package org.apache.logging.log4j.junit;

import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

/**
 * JUnit {@link TestRule} for constructing a new LoggerContext using a specified configuration file.
 */
public class InitialLoggerContext implements TestRule {

    private final String configLocation;

    private LoggerContext context;

    public InitialLoggerContext(String configLocation) {
        this.configLocation = configLocation;
    }

    @Override
    public Statement apply(final Statement base, final Description description) {
        return new Statement() {
            @Override
            public void evaluate() throws Throwable {
                context = Configurator.initialize(
                        description.getDisplayName(),
                        description.getTestClass().getClassLoader(),
                        configLocation
                );
                try {
                    base.evaluate();
                } finally {
                    Configurator.shutdown(context);
                }
            }
        };
    }

    public LoggerContext getContext() {
        return context;
    }
}

@@ -71,29 +71,180 @@
 4j.core.
-LoggerContext
+Appender;%0Aimport org.apache.logging.log4j.core.Logger;%0Aimport org.apache.logging.log4j.core.LoggerContext;%0Aimport org.apache.logging.log4j.core.config.Configuration
 ;%0Aimport
@@ -1457,11 +1457,323 @@
 t;%0A    %7D
+%0A%0A    public Logger getLogger(final String name) %7B%0A        return context.getLogger(name);%0A    %7D%0A%0A    public Configuration getConfiguration() %7B%0A        return context.getConfiguration();%0A    %7D%0A%0A    public Appender getAppender(final String name) %7B%0A        return getConfiguration().getAppenders().get(name);%0A    %7D
 %0A%7D%0A

Add some convenience methods to InitialLoggerContext.