Package org.apache.logging.log4j

Examples of org.apache.logging.log4j.Logger


    @Test
    public void testFlushAtEndOfBatch() throws Exception {
        File f = new File("target", "FastFileAppenderTest.log");
        // System.out.println(f.getAbsolutePath());
        f.delete();
        Logger log = LogManager.getLogger("com.foo.Bar");
        String msg = "Message flushed with immediate flush=false";
        log.info(msg);
        ((LifeCycle) LogManager.getContext()).stop(); // stop async thread

        BufferedReader reader = new BufferedReader(new FileReader(f));
        String line1 = reader.readLine();
        reader.close();
View Full Code Here


    @Test
    public void testLocationIncluded() throws Exception {
        File f = new File("target", "FastRollingFileAppenderLocationTest.log");
        // System.out.println(f.getAbsolutePath());
        f.delete();
        Logger log = LogManager.getLogger("com.foo.Bar");
        String msg = "Message with location, flushed with immediate flush=false";
        log.info(msg);
        ((LifeCycle) LogManager.getContext()).stop(); // stop async thread

        BufferedReader reader = new BufferedReader(new FileReader(f));
        String line1 = reader.readLine();
        reader.close();
View Full Code Here

        // System.out.println(f.getAbsolutePath());
        File after1 = new File("target", "afterRollover-1.log");
        f.delete();
        after1.delete();

        Logger log = LogManager.getLogger("com.foo.Bar");
        String msg = "First a short message that does not trigger rollover";
        log.info(msg);
        Thread.sleep(50);

        BufferedReader reader = new BufferedReader(new FileReader(f));
        String line1 = reader.readLine();
        assertTrue(line1.contains(msg));
        reader.close();

        assertFalse("afterRollover-1.log not created yet", after1.exists());

        String exceed = "Long message that exceeds rollover size... ";
        char[] padding = new char[250];
        Arrays.fill(padding, 'X');
        exceed += new String(padding);
        log.warn(exceed);
        assertFalse("exceeded size but afterRollover-1.log not created yet", after1.exists());

        String trigger = "This message triggers rollover.";
        log.warn(trigger);

        ((LifeCycle) LogManager.getContext()).stop(); // stop async thread

        assertTrue("afterRollover-1.log created", after1.exists());
View Full Code Here

    @Test
    public void testFlushAtEndOfBatch() throws Exception {
        File f = new File("target", "FastRollingFileAppenderTest.log");
        // System.out.println(f.getAbsolutePath());
        f.delete();
        Logger log = LogManager.getLogger("com.foo.Bar");
        String msg = "Message flushed with immediate flush=false";
        log.info(msg);
        ((LifeCycle) LogManager.getContext()).stop(); // stop async thread

        BufferedReader reader = new BufferedReader(new FileReader(f));
        String line1 = reader.readLine();
        reader.close();
View Full Code Here

            System.err.println("Initializing server");
            testServer = new TestSocketServer();
            futureIn = executor.submit(testServer);

            //System.err.println("Initializing logger");
            final Logger logger = LogManager.getLogger(SocketMessageLossTest.class);

            String message = "Log #1";
            logger.error(message);

            final BufferedReader reader = new BufferedReader(new InputStreamReader(futureIn.get()));
            assertEquals(message, reader.readLine());

            //System.err.println("Closing server");
            closeQuietly(testServer);
            assertTrue("Server not shutdown", testServer.server.isClosed());

            //System.err.println("Sleeping to ensure no race conditions");
            Thread.sleep(1000);

            message = "Log #2";
            try {
                logger.error(message);
                fail("Expected exception not thrown");
            } catch (final AppenderRuntimeException e) {
                // An exception is expected.
            }

            message = "Log #3";
            try {
                logger.error(message);
                fail("Expected exception not thrown");
            } catch (final AppenderRuntimeException e) {
                // An exception is expected.
            }
        } finally {
View Full Code Here

    }

    @Test
    public void testBadFilterParam() throws Exception {
        final LoggerContext ctx = Configurator.initialize("Test1", null, "bad/log4j-badfilterparam.xml");
        final Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
        final Configuration config = ctx.getConfiguration();
        assertNotNull("No configuration", config);
        assertTrue("Unexpected configuration", "XMLConfigTest".equals(config.getName()));
        final LoggerConfig lcfg = config.getLoggerConfig("org.apache.logging.log4j.test1");
        assertNotNull("No Logger", lcfg);
View Full Code Here

    }

    @Test
    public void testNoFilters() throws Exception {
        final LoggerContext ctx = Configurator.initialize("Test1", null, "bad/log4j-nofilter.xml");
        final Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
        final Configuration config = ctx.getConfiguration();
        assertNotNull("No configuration", config);
        assertTrue("Unexpected configuration", "XMLConfigTest".equals(config.getName()));
        final LoggerConfig lcfg = config.getLoggerConfig("org.apache.logging.log4j.test1");
        assertNotNull("No Logger", lcfg);
View Full Code Here

    }

    @Test
    public void testBadLayout() throws Exception {
        final LoggerContext ctx = Configurator.initialize("Test1", null, "bad/log4j-badlayout.xml");
        final Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
        final Configuration config = ctx.getConfiguration();
        assertNotNull("No configuration", config);
        assertTrue("Unexpected configuration", "XMLConfigTest".equals(config.getName()));
    }
View Full Code Here

            dir.append(element.toUpperCase());
        }
        final String value = FILESEP.equals("/") ? dir.toString() + "/test.log" : "1:/target/bad:file.log";
        System.setProperty("testfile", value);
        final LoggerContext ctx = Configurator.initialize("Test1", null, "bad/log4j-badfilename.xml");
        final Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
        final Configuration config = ctx.getConfiguration();
        assertNotNull("No configuration", config);
        assertTrue("Unexpected configuration", "XMLConfigTest".equals(config.getName()));
        assertTrue("Create bad appender", config.getAppenders().size() == 2);
    }
View Full Code Here

    }


    @Test
    public void testProperties() {
        final Logger logger = LogManager.getLogger(RewriteAppenderTest.class);
        logger.debug("Test properties rewrite");
        final List<String> list = app2.getMessages();
        assertNotNull("No events generated", list);
        assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
        assertFalse("Did not resolve user name", list.get(0).contains("{user.dir}"));
    }
View Full Code Here

TOP

Related Classes of org.apache.logging.log4j.Logger

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.