org.apache.logging.log4j.core.impl.DefaultLogEventFactory Java Examples

The following examples show how to use org.apache.logging.log4j.core.impl.DefaultLogEventFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogEventFactoryTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            System.setProperty(Constants.LOG4J_LOG_EVENT_FACTORY, TestLogEventFactory.class.getName());
            resetLogEventFactory(new TestLogEventFactory());
            try {
                base.evaluate();
            } finally {
                System.clearProperty(Constants.LOG4J_LOG_EVENT_FACTORY);
                resetLogEventFactory(new DefaultLogEventFactory());
            }
        }

        private void resetLogEventFactory(final LogEventFactory logEventFactory) throws IllegalAccessException {
            final Field field = FieldUtils.getField(LoggerConfig.class, "LOG_EVENT_FACTORY", true);
            FieldUtils.removeFinalModifier(field, true);
            FieldUtils.writeStaticField(field, logEventFactory, false);
        }
    };
}
 
Example #2
Source File: AppenderRefFailoverPolicy.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Extension point - let's allow to customize e.g.: LogEvent type or any other param
 *
 * @param failedPayload payload to be handled
 */
protected void doDeliver(String failedPayload) {
    appenderControl.callAppender(DefaultLogEventFactory.getInstance().createEvent(appenderRef.getRef(),
            null,
            getClass().getName(),
            appenderRef.getLevel(),
            new SimpleMessage(failedPayload),
            null,
            null));
}
 
Example #3
Source File: ElasticsearchAppenderTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
private LogEvent createTestLogEvent() {
    return DefaultLogEventFactory.getInstance().createEvent("testLogger",
            null,
            getClass().getName(),
            Level.INFO,
            new SimpleMessage("testMessage"),
            null,
            null);

}
 
Example #4
Source File: RoutesScriptAppenderTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoutingAppenderRoutes() {
    final RoutingAppender routingAppender = getRoutingAppender();
    assertEquals(expectBindingEntries, routingAppender.getDefaultRouteScript() != null);
    assertEquals(expectBindingEntries, routingAppender.getDefaultRoute() != null);
    final Routes routes = routingAppender.getRoutes();
    Assert.assertNotNull(routes);
    Assert.assertNotNull(routes.getPatternScript());
    final LogEvent logEvent = DefaultLogEventFactory.getInstance().createEvent("", null, "", Level.ERROR, null,
            null, null);
    assertEquals("Service2", routes.getPattern(logEvent, new ConcurrentHashMap<>()));
}
 
Example #5
Source File: AsyncLoggerConfigErrorOnFormat.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() {
    System.setProperty("log4j2.is.webapp", "false");
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "AsyncLoggerConfigErrorOnFormat.xml");
    // Log4jLogEvent.toString invokes message.toString
    System.setProperty("log4j2.logEventFactory", DefaultLogEventFactory.class.getName());
}
 
Example #6
Source File: AbstractStringLayout.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
private DefaultLogEventFactory getLogEventFactory() {
    return DefaultLogEventFactory.getInstance();
}