Java Code Examples for org.apache.logging.log4j.core.config.AppenderControl#getAppender()
The following examples show how to use
org.apache.logging.log4j.core.config.AppenderControl#getAppender() .
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: Log4J2Logger.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Nullable @Override public String fileName() { for (Logger log = impl; log != null; log = log.getParent()) { for (Appender a : log.getAppenders().values()) { if (a instanceof FileAppender) return ((FileAppender)a).getFileName(); if (a instanceof RollingFileAppender) return ((RollingFileAppender)a).getFileName(); if (a instanceof RoutingAppender) { try { RoutingAppender routing = (RoutingAppender)a; Field appsFiled = routing.getClass().getDeclaredField("appenders"); appsFiled.setAccessible(true); Map<String, AppenderControl> appenders = (Map<String, AppenderControl>)appsFiled.get(routing); for (AppenderControl control : appenders.values()) { Appender innerApp = control.getAppender(); if (innerApp instanceof FileAppender) return normalize(((FileAppender)innerApp).getFileName()); if (innerApp instanceof RollingFileAppender) return normalize(((RollingFileAppender)innerApp).getFileName()); } } catch (IllegalAccessException | NoSuchFieldException e) { error("Failed to get file name (was the implementation of log4j2 changed?).", e); } } } } return null; }
Example 2
Source File: DefaultRouteScriptAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private ListAppender getListAppender() { final String key = "Service2"; final RoutingAppender routingAppender = getRoutingAppender(); Assert.assertTrue(routingAppender.isStarted()); final Map<String, AppenderControl> appenders = routingAppender.getAppenders(); final AppenderControl appenderControl = appenders.get(key); assertNotNull("No appender control generated for '" + key + "'; appenders = " + appenders, appenderControl); final ListAppender listAppender = (ListAppender) appenderControl.getAppender(); return listAppender; }
Example 3
Source File: RoutesScriptAppenderTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private ListAppender getListAppender() { final String key = "Service2"; final RoutingAppender routingAppender = getRoutingAppender(); Assert.assertTrue(routingAppender.isStarted()); final Map<String, AppenderControl> appenders = routingAppender.getAppenders(); final AppenderControl appenderControl = appenders.get(key); assertNotNull("No appender control generated for '" + key + "'; appenders = " + appenders, appenderControl); return (ListAppender) appenderControl.getAppender(); }