Package org.apache.logging.log4j.core.impl

Examples of org.apache.logging.log4j.core.impl.Log4jLogEvent


                    }
                }
            }
        }
        final MapMessage message = ((MapMessage) msg).newInstance(newMap);
        return new Log4jLogEvent(source.getLoggerName(), source.getMarker(), source.getFQCN(), source.getLevel(),
            message, source.getThrown(), source.getContextMap(), source.getContextStack(), source.getThreadName(),
            source.getSource(), source.getMillis());
    }
View Full Code Here


            final Property prop = entry.getKey();
            props.put(prop.getName(), entry.getValue() ?
                config.getSubst().replace(prop.getValue()) : prop.getValue());
        }

        return new Log4jLogEvent(source.getLoggerName(), source.getMarker(), source.getFQCN(), source.getLevel(),
            source.getMessage(), source.getThrown(), props, source.getContextStack(), source.getThreadName(),
            source.getSource(), source.getMillis());
    }
View Full Code Here

                    }
                } catch (final InterruptedException ex) {
                    // No good reason for this.
                    continue;
                }
                final Log4jLogEvent event = Log4jLogEvent.deserialize(s);
                event.setEndOfBatch(queue.isEmpty());
                boolean success = false;
                for (final AppenderControl<?> control : appenders) {
                    try {
                        control.callAppender(event);
                        success = true;
                    } catch (final Exception ex) {
                        // If no appender is successful the error appender will get it.
                    }
                }
                if (!success && errorAppender != null) {
                    try {
                        errorAppender.callAppender(event);
                    } catch (final Exception ex) {
                        // Silently accept the error.
                    }
                }
            }
            // Process any remaining items in the queue.
            while (!queue.isEmpty()) {
                try {
                    Serializable s = queue.take();
                    if (s instanceof Log4jLogEvent) {
                        final Log4jLogEvent event = Log4jLogEvent.deserialize(s);
                        event.setEndOfBatch(queue.isEmpty());
                        for (final AppenderControl<?> control : appenders) {
                            control.callAppender(event);
                        }
                    }
                } catch (final InterruptedException ex) {
View Full Code Here

     * @return The LogEvent.
     */
    public LogEvent createEvent(final String loggerName, final Marker marker,
            final String fqcn, final Level level, final Message data,
            final List<Property> properties, final Throwable t) {
        return new Log4jLogEvent(loggerName, marker, fqcn, level, data,
                properties, t);
    }
View Full Code Here

    public void testFollow() {
        final PrintStream ps = System.out;
        final Layout layout = PatternLayout.createLayout(null, null, null, null);
        final ConsoleAppender 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 layout = PatternLayout.createLayout(null, null, null, null);
        final InMemoryAppender app = new InMemoryAppender("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

@Plugin(name = "TestRewritePolicy", type = "Core", elementType = "rewritePolicy", printObject = true)
public class TestRewritePolicy implements RewritePolicy {

    public LogEvent rewrite(final LogEvent source) {

        return new Log4jLogEvent(source.getLoggerName(), source.getMarker(), source.getFQCN(), source.getLevel(),
            source.getMessage(), source.getThrown(), source.getContextMap(), source.getContextStack(),
            source.getThreadName(), source.getSource(), source.getMillis());
    }
View Full Code Here

  @BeforeClass
  public static void setupClass() {
    map.put("test1", "one");
    map.put("test2", "two");
    logEvent0 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
        new SimpleMessage("Test"), new RuntimeException("test"), map, null, "none",
        new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 28), 2);
    logEvent1 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
        new MapMessage(map), null, map, null, "none",
        new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 29), 2);
    logEvent2 = new Log4jLogEvent("test", MarkerManager.getMarker("test"), "MapRewritePolicyTest.setupClass()",
        Level.TRACE, new StructuredDataMessage("test", "Nothing", "test", map), new RuntimeException("test"), null,
        new ThreadContext.ImmutableStack(map.values()), "none", new StackTraceElement("MapRewritePolicyTest",
        "setupClass", "MapRewritePolicyTest", 30), 20000000);
    logEvent3 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ALL, new MapMessage(map),
        null, map, new ThreadContext.ImmutableStack(map.values()), null, new StackTraceElement("MapRewritePolicyTest",
        "setupClass", "MapRewritePolicyTest", 31), Long.MAX_VALUE);
    rewrite = new KeyValuePair[] {new KeyValuePair("test2", "2"), new KeyValuePair("test3", "three")};
  }
View Full Code Here

    @Test
    public void testRegex() throws Exception {
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        final PatternLayout layout = PatternLayout.createLayout(regexPattern, ctx.getConfiguration(),
            null, null);
        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

        RegexFilter filter = RegexFilter.createFilter(".* test .*", null, null, null);
        filter.start();
        assertTrue(filter.isStarted());
        assertTrue(filter.filter(null, Level.DEBUG, null, "This is a test message", (Throwable)null) == Filter.Result.NEUTRAL);
        assertTrue(filter.filter(null, Level.ERROR, null, "This is not a test", (Throwable)null) == Filter.Result.DENY);
        LogEvent event = new Log4jLogEvent(null, null, null, Level.DEBUG, new SimpleMessage("Another test message"), null);
        assertTrue(filter.filter(event) == Filter.Result.NEUTRAL);
        event = new Log4jLogEvent(null, null, null, Level.ERROR, new SimpleMessage("test"), null);
        assertTrue(filter.filter(event) == Filter.Result.DENY);
        filter = RegexFilter.createFilter("* test *", null, null, null);
        assertNull(filter);
    }
View Full Code Here

TOP

Related Classes of org.apache.logging.log4j.core.impl.Log4jLogEvent

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.