Package org.apache.logging.log4j.core

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


            "false", "false", layout, null, "false", null, null);
        final Thread t = Thread.currentThread();
        app.start();
        assertTrue("Appender did not start", app.isStarted());
        for (int i=0; i < count; ++i) {
            final LogEvent event = new Log4jLogEvent("TestLogger", null, FileAppenderTest.class.getName(), Level.INFO,
                new SimpleMessage("Test"), null, null, null, name, null, System.currentTimeMillis());
            try {
                app.append(event);
                t.sleep(25)// Give up control long enough for another thread/process to occasionally do something.
            } catch (final Exception ex) {
View Full Code Here


    public void testFollow() {
        final PrintStream ps = System.out;
        final Layout<String> layout = PatternLayout.createLayout(null, null, null, null);
        final ConsoleAppender<String> app = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "true", "false");
        app.start();
        final LogEvent event = new Log4jLogEvent("TestLogger", null, ConsoleAppenderTest.class.getName(), Level.INFO,
            new SimpleMessage("Test"), null);

        assertTrue("Appender did not start", app.isStarted());
        System.setOut(new PrintStream(baos));
        app.append(event);
View Full Code Here

    @Test
    public void testAppender() {
        final Layout<String> layout = PatternLayout.createLayout(null, null, null, null);
        final InMemoryAppender<String> app = new InMemoryAppender<String>("test", layout, null, false);
        final LogEvent event = new Log4jLogEvent("TestLogger", null, OutputStreamAppenderTest.class.getName(), Level.INFO,
            new SimpleMessage("Test"), null);
        app.start();
        assertTrue("Appender did not start", app.isStarted());
        app.append(event);
        final String msg = app.toString();
View Full Code Here

        root.trace("Discarded Message");
        root.trace("Discarded Message");

        final List<LogEvent> msgs = appender.getEvents();
        assertEquals(1, msgs.size());
        final LogEvent event = msgs.get(0);
        assertEquals(org.apache.logging.log4j.Level.TRACE, event.getLevel());
        assertEquals("Message 1", event.getMessage().getFormat());
        appender.stop();
        root.getLogger().removeAppender(appender);
    }
View Full Code Here

        root.trace("Discarded Message", ex);
        root.trace("Discarded Message", ex);

        final List<LogEvent> msgs = appender.getEvents();
        assertEquals(1, msgs.size());
        final LogEvent event = msgs.get(0);
        assertEquals(org.apache.logging.log4j.Level.TRACE, event.getLevel());
        assertEquals("Message 1", event.getMessage().getFormattedMessage());
        appender.stop();
        root.getLogger().removeAppender(appender);
    }
View Full Code Here

        category.getLogger().addAppender(appender);
        category.info("Hello, World");
        final List<LogEvent> list = appender.getEvents();
        int events = list.size();
        assertTrue("Number of events should be 1, was " + events, events == 1);
        LogEvent event = list.get(0);
        Message msg = event.getMessage();
        assertNotNull("No message", msg);
        assertTrue("Incorrect Message type", msg instanceof ObjectMessage);
        Object[] objects = msg.getParameters();
        assertTrue("Incorrect Object type", objects[0] instanceof String);
        appender.clear();
        category.log(Priority.INFO, "Hello, World");
        events = list.size();
        assertTrue("Number of events should be 1, was " + events, events == 1);
        event = list.get(0);
        msg = event.getMessage();
        assertNotNull("No message", msg);
        assertTrue("Incorrect Message type", msg instanceof ObjectMessage);
        objects = msg.getParameters();
        assertTrue("Incorrect Object type", objects[0] instanceof String);
        appender.clear();
View Full Code Here

        public void run() {
            boolean closed = false;
            try {
                try {
                    while (!shutdown) {
                        final LogEvent event = (LogEvent) ois.readObject();
                        if (event != null) {
                            log(event);
                        }
                    }
                } catch (final EOFException eof) {
View Full Code Here

            try {
                byte[] buf = new byte[maxBufferSize];
                DatagramPacket packet = new DatagramPacket(buf, buf.length);
                server.receive(packet);
                ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(packet.getData(), packet.getOffset(), packet.getLength()));
                final LogEvent event = (LogEvent) ois.readObject();
                if (event != null) {
                    log(event);
                }
            } catch (final OptionalDataException opt) {
                logger.error("OptionalDataException eof=" + opt.eof + " length=" + opt.length, opt);
View Full Code Here

                final String value = entry.getValue() ? config.getSubst()
                        .replace(prop.getValue()) : prop.getValue();
                props.add(Property.createProperty(prop.getName(), value));
            }
        }
        final LogEvent event = logEventFactory.createEvent(loggerName, marker,
                fqcn, level, data, props, t);
        log(event);
    }
View Full Code Here

        msg.put("Key2", "Value2");
        EventLogger.logEvent(msg);
        final List<LogEvent> list = app.getEvents();
        assertNotNull("No events generated", list);
        assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
        final LogEvent event = list.get(0);
        final Message m = event.getMessage();
        assertTrue("Message is not a MapMessage", m instanceof MapMessage);
        final MapMessage message = (MapMessage) m;
        final Map<String, String> map = message.getData();
        assertNotNull("No Map", map);
        assertTrue("Incorrect number of map entries, expected 3 got " + map.size(), map.size() == 3);
View Full Code Here

TOP

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

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.