Package org.apache.logging.log4j.core

Examples of org.apache.logging.log4j.core.LoggerContext


        assertEquals("The return value is not correct.", Tag.EVAL_PAGE, this.tag.doEndTag());
        verify("catching WARN M-CATCHING[ EXCEPTION ] E java.lang.Error: This is the last test.");
    }

    private void verify(final String expected) {
        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        final Appender listApp = ctx.getConfiguration().getAppender("List");
        assertNotNull("Missing Appender", listApp);
        assertTrue("Not a ListAppender", listApp instanceof ListAppender);
        final List<String> events = ((ListAppender) listApp).getMessages();
        try
        {
View Full Code Here


    private static final String CONFIG = "log4j-fatalOnly.xml";

    @BeforeClass
    public static void beforeClass() {
        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
        LoggerContext ctx = (LoggerContext) LogManager.getContext();
        ctx.reconfigure();
        StatusLogger logger = StatusLogger.getLogger();
        logger.setLevel(Level.FATAL);
    }
View Full Code Here

    @BeforeClass
    public static void setupClass() {
        ThreadContext.clearAll();
        ConfigurationFactory.setConfigurationFactory(cf);
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        ctx.reconfigure();
    }
View Full Code Here

    }

    @BeforeClass
    public static void setupClass() {
        ConfigurationFactory.setConfigurationFactory(cf);
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        ctx.reconfigure();
    }
View Full Code Here

        }
    }

    @Test
    public void testRegex() throws Exception {
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        final PatternLayout layout = PatternLayout.newBuilder()
            .withPattern(regexPattern)
            .withConfiguration(ctx.getConfiguration())
            .build();
        final LogEvent event = new Log4jLogEvent(this.getClass().getName(), null,
                "org.apache.logging.log4j.core.Logger", Level.INFO, new SimpleMessage("Hello, world!"), null);
        final byte[] result = layout.toByteArray(event);
        assertEquals("org/apache/logging/log4j/core/layout/PatternLayoutTest Hello, world!", new String(result));
View Full Code Here

        final byte[] result = layout.toByteArray(event);
        assertEquals("org/apache/logging/log4j/core/layout/PatternLayoutTest Hello, world!", new String(result));
    }

    private void testUnixTime(String pattern) throws Exception {
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        final PatternLayout layout = PatternLayout.newBuilder()
            .withPattern(pattern + " %m")
            .withConfiguration(ctx.getConfiguration())
            .build();
        final LogEvent event1 = new Log4jLogEvent(this.getClass().getName(), null,
                "org.apache.logging.log4j.core.Logger", Level.INFO, new SimpleMessage("Hello, world 1!"), null);
        final byte[] result1 = layout.toByteArray(event1);
        assertEquals(event1.getTimeMillis() + " Hello, world 1!", new String(result1));
View Full Code Here

        // System.out.println("event2=" + event2.getMillis());
    }

    @Test
    public void testUnixTime() throws Exception {
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        final PatternLayout layout = PatternLayout.newBuilder()
            .withPattern("%d{UNIX} %m")
            .withConfiguration(ctx.getConfiguration())
            .build();
        final LogEvent event1 = new Log4jLogEvent(this.getClass().getName(), null,
                "org.apache.logging.log4j.core.Logger", Level.INFO, new SimpleMessage("Hello, world 1!"), null);
        final byte[] result1 = layout.toByteArray(event1);
        assertEquals(event1.getTimeMillis() / 1000 + " Hello, world 1!", new String(result1));
View Full Code Here

        // System.out.println("event2=" + event2.getTimeMillis() / 1000);
    }

    @Test
    public void testUnixTimeMillis() throws Exception {
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        final PatternLayout layout = PatternLayout.newBuilder()
            .withPattern("%d{UNIX_MILLIS} %m")
            .withConfiguration(ctx.getConfiguration())
            .build();
        final LogEvent event1 = new Log4jLogEvent(this.getClass().getName(), null,
                "org.apache.logging.log4j.core.Logger", Level.INFO, new SimpleMessage("Hello, world 1!"), null);
        final byte[] result1 = layout.toByteArray(event1);
        assertEquals(event1.getTimeMillis() + " Hello, world 1!", new String(result1));
View Full Code Here

        // System.out.println("event2=" + event2.getTimeMillis());
    }

    @Test
    public void testHeaderFooter() throws Exception {
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        final PatternLayout layout = PatternLayout.newBuilder()
            .withPattern("%d{UNIX} %m")
            .withConfiguration(ctx.getConfiguration())
            .withHeader("${ctx:header}")
            .withFooter("${ctx:footer}")
            .build();
        ThreadContext.put("header", "Hello world Header");
        ThreadContext.put("footer", "Hello world Footer");
View Full Code Here

public class AsyncLoggerContextSelectorTest {

    @Test
    public void testContextReturnsAsyncLoggerContext() {
        final AsyncLoggerContextSelector selector = new AsyncLoggerContextSelector();
        final LoggerContext context = selector.getContext(null, null, false);

        assertTrue(context instanceof AsyncLoggerContext);
    }
View Full Code Here

TOP

Related Classes of org.apache.logging.log4j.core.LoggerContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.