Java Code Examples for org.apache.logging.log4j.core.config.Configurator#shutdown()

The following examples show how to use org.apache.logging.log4j.core.config.Configurator#shutdown() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsoleAppenderJAnsiXExceptionMain.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
public void test(final String[] args) {
    System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
    // System.out.println(System.getProperty("java.class.path"));
    final String config = args == null || args.length == 0 ? "target/test-classes/log4j2-console-xex-ansi.xml"
            : args[0];
    final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
    final Logger logger = LogManager.getLogger(ConsoleAppenderJAnsiXExceptionMain.class);
    try {
        Files.getFileStore(Paths.get("?BOGUS?"));
    } catch (final Exception e) {
        final IllegalArgumentException logE = new IllegalArgumentException("Bad argument foo", e);
        logger.error("Gotcha!", logE);
    } finally {
        Configurator.shutdown(ctx);
    }
}
 
Example 2
Source File: XmlCompactFileAppenderValidationTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void validateXmlSchemaThrowable() throws Exception {
    final File file = new File("target", "XmlCompactFileAppenderValidationTest.log.xml");
    file.delete();
    final Logger log = LogManager.getLogger("com.foo.Bar");
    try {
        throw new IllegalArgumentException("IAE");
    } catch (final IllegalArgumentException e) {
        log.warn("Message 1", e);
    }
    Configurator.shutdown(this.loggerContext);
    this.validateXmlSchema(file);
}
 
Example 3
Source File: XmlCompactFileAppenderValidationTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void validateXmlSchema() throws Exception {
    final File file = new File("target", "XmlCompactFileAppenderValidationTest.log.xml");
    file.delete();
    final Logger log = LogManager.getLogger("com.foo.Bar");
    log.warn("Message 1");
    log.info("Message 2");
    log.debug("Message 3");
    Configurator.shutdown(this.loggerContext);
    this.validateXmlSchema(file);
}
 
Example 4
Source File: XmlCompactFileAppenderValidationTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void validateXmlNoEvents() throws Exception {
    final File file = new File("target", "XmlCompactFileAppenderValidationTest.log.xml");
    file.delete();
    Configurator.shutdown(this.loggerContext);
    this.validateXmlSchema(file);
}
 
Example 5
Source File: LoggerContextRule.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    // Hack: Using -DEBUG as a JVM param sets a property called "EBUG"...
    if (System.getProperties().containsKey("EBUG")) {
        StatusLogger.getLogger().setLevel(Level.DEBUG);
    }
    testClassName = description.getClassName();
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            if (contextSelectorClass != null) {
                System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, contextSelectorClass.getName());
            }
            // TODO Consider instead of the above:
            // LogManager.setFactory(new Log4jContextFactory(LoaderUtil.newInstanceOf(contextSelectorClass)));
            System.setProperty(SYS_PROP_KEY_CLASS_NAME, description.getClassName());
            System.setProperty(SYS_PROP_KEY_DISPLAY_NAME, description.getDisplayName());
            loggerContext = Configurator.initialize(description.getDisplayName(),
                    description.getTestClass().getClassLoader(), configurationLocation);
            try {
                base.evaluate();
            } finally {
                if (!Configurator.shutdown(loggerContext, shutdownTimeout, shutdownTimeUnit)) {
                    StatusLogger.getLogger().error("Logger context {} did not shutdown completely after {} {}.",
                            loggerContext.getName(), shutdownTimeout, shutdownTimeUnit);
                }
                loggerContext = null;
                contextSelectorClass = null;
                StatusLogger.getLogger().reset();
                System.clearProperty(Constants.LOG4J_CONTEXT_SELECTOR);
                System.clearProperty(SYS_PROP_KEY_CLASS_NAME);
                System.clearProperty(SYS_PROP_KEY_DISPLAY_NAME);
            }
        }
    };

}
 
Example 6
Source File: XmlCompactFileAppenderValidationTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
    // Just in case, an @Test blew up
    Configurator.shutdown(this.loggerContext);
}
 
Example 7
Source File: VelocityTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDownClass() {
    Configurator.shutdown(context);
    StatusLogger.getLogger().reset();
}
 
Example 8
Source File: VelocityTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDownClass() {
    Configurator.shutdown(context);
    StatusLogger.getLogger().reset();
}
 
Example 9
Source File: LateConfigTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void tearDownClass() {
    Configurator.shutdown(context);
    StatusLogger.getLogger().reset();
}
 
Example 10
Source File: SocketReconnectTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void afterClass() {
    Configurator.shutdown(loggerContext);
}