@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); } }; }
/** * 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)); }
private LogEvent createTestLogEvent() { return DefaultLogEventFactory.getInstance().createEvent("testLogger", null, getClass().getName(), Level.INFO, new SimpleMessage("testMessage"), null, null); }
@Test public void testRoutingAppenderRoutes() { final RoutingAppender routingAppender = getRoutingAppender(); Assert.assertEquals(expectBindingEntries, routingAppender.getDefaultRouteScript() != null); Assert.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); Assert.assertEquals("Service2", routes.getPattern(logEvent, new ConcurrentHashMap<>())); }
private DefaultLogEventFactory getLogEventFactory() { return DefaultLogEventFactory.getInstance(); }