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


    @Test
    public void testFull() {
        final RootThrowablePatternConverter converter = RootThrowablePatternConverter.newInstance(null);
        final Throwable cause = new NullPointerException("null pointer");
        final Throwable parent = new IllegalArgumentException("IllegalArgument", cause);
        final LogEvent event = new Log4jLogEvent("testLogger", null, this.getClass().getName(), Level.DEBUG,
            new SimpleMessage("test exception"), parent);
        final StringBuilder sb = new StringBuilder();
        converter.format(event, sb);
        final String result = sb.toString();
        //System.out.print(result);
View Full Code Here


    @Test
    public void testLevel() {
        final Message msg = new SimpleMessage("Hello");
        LogEvent event = new Log4jLogEvent("MyLogger", null, null, Level.DEBUG, msg, null);
        final StringBuilder sb = new StringBuilder();
        LevelPatternConverter converter = LevelPatternConverter.newInstance(null);
        converter.format(event, sb);
        assertEquals(Level.DEBUG.toString(), sb.toString());
        final String[] opts = new String[] {"WARN=Warning, DEBUG=Debug, ERROR=Error, TRACE=Trace, INFO=Info"};
View Full Code Here

    @Test
    public void testPolicy() {
        OnStartupTriggeringPolicy policy = OnStartupTriggeringPolicy.createPolicy();
        final MyRollingManager manager = new MyRollingManager(policy, null);
        manager.setFileTime(System.currentTimeMillis() - 36000000);
        final LogEvent event = new Log4jLogEvent(null, null, null, Level.ERROR, new SimpleMessage("Test"), null);
        assertTrue("Expected trigger to succeed", policy.isTriggeringEvent(event));
        assertTrue("Expected trigger not to fire", !policy.isTriggeringEvent(event));
        policy = OnStartupTriggeringPolicy.createPolicy();
        policy.initialize(manager);
        manager.setFileTime(System.currentTimeMillis());
View Full Code Here

        final Exception parent = new IllegalStateException("Test");
        final Throwable child = new LoggingException("This is a test");
        root.error("Throwing an exception", child);
        root.debug("This is another test message");
        Thread.sleep(250);
        LogEvent event = list.poll(3, TimeUnit.SECONDS);
        assertNotNull("No event retrieved", event);
        assertTrue("Incorrect event", event.getMessage().getFormattedMessage().equals("This is a test message"));
        assertTrue("Message not delivered via TCP", tcpCount > 0);
        event = list.poll(3, TimeUnit.SECONDS);
        assertNotNull("No event retrieved", event);
        assertTrue("Incorrect event", event.getMessage().getFormattedMessage().equals("Throwing an exception"));
        assertTrue("Message not delivered via TCP", tcpCount > 1);
    }
View Full Code Here

        filter.start();
        assertTrue(filter.isStarted());
        final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/LosAngeles"));
        cal.set(Calendar.HOUR_OF_DAY, 02);
        long tod = cal.getTimeInMillis();
        LogEvent event = new Log4jLogEvent(null, null, null, null, null, null, null, null, null, null, tod);
        assertTrue(filter.filter(null, Level.ERROR, null, null, (Throwable)null) == Filter.Result.NEUTRAL);
        assertTrue(filter.filter(event) == Filter.Result.NEUTRAL);
        cal.roll(Calendar.DAY_OF_MONTH, true);
        tod = cal.getTimeInMillis();
        event = new Log4jLogEvent(null, null, null, null, null, null, null, null, null, null, tod);
View Full Code Here

        // set appender on root and set level to debug
        root.addAppender(appender);
        root.setAdditive(false);
        root.setLevel(Level.DEBUG);
        root.debug("This is a udp message");
        final LogEvent event = list.poll(3, TimeUnit.SECONDS);
        assertNotNull("No event retrieved", event);
        assertTrue("Incorrect event", event.getMessage().getFormattedMessage().equals("This is a udp message"));
        assertTrue("Message not delivered via UDP", udpCount > 0);
    }
View Full Code Here

            new TCPSocketServer(PORTNUM2).start();

            root.debug("This message is written because a deadlock never.");

            LogEvent event = list.poll(3, TimeUnit.SECONDS);
            assertNotNull("No event retrieved", event);
    }
View Full Code Here

        assertTrue(filter.filter(null, Level.DEBUG, null, null, (Throwable)null) == Filter.Result.NEUTRAL);
        assertTrue(filter.filter(null, Level.ERROR, null, null, (Throwable)null) == Filter.Result.NEUTRAL);
        ThreadContext.clear();
        ThreadContext.put("userid", "JohnDoe");
        ThreadContext.put("organization", "apache");
        LogEvent event = new Log4jLogEvent(null, null, null, Level.DEBUG, new SimpleMessage("Test"), null);
        assertTrue(filter.filter(event) == Filter.Result.DENY);
        event = new Log4jLogEvent(null, null, null, Level.ERROR, new SimpleMessage("Test"), null);
        assertTrue(filter.filter(event) == Filter.Result.NEUTRAL);
        ThreadContext.clear();
    }
View Full Code Here

                    }
                    final int eventEndMarkerIndex = pair[1];
                    if (eventEndMarkerIndex > 0) {
                        final int eventEndXmlIndex = eventEndMarkerIndex + eventEndMarker.length();
                        final String textEvent = workingText = text.substring(eventStartMarkerIndex, eventEndXmlIndex);
                        final LogEvent logEvent = unmarshal(textEvent);
                        logEventListener.log(logEvent);
                        beginIndex = eventEndXmlIndex;
                    } else {
                        // No more events or partial XML only in the buffer.
                        // Save the unprocessed string part
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.