Search in sources :

Example 1 with RoutingAppender

use of org.apache.logging.log4j.core.appender.routing.RoutingAppender in project ignite by apache.

the class Log4J2Logger method fileName.

/** {@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 normilize(((FileAppender) innerApp).getFileName());
                        if (innerApp instanceof RollingFileAppender)
                            return normilize(((RollingFileAppender) innerApp).getFileName());
                    }
                } catch (IllegalAccessException | NoSuchFieldException e) {
                    error("Failed to get file name (was the implementation of log4j2 changed?).", e);
                }
            }
        }
    }
    return null;
}
Also used : Appender(org.apache.logging.log4j.core.Appender) RoutingAppender(org.apache.logging.log4j.core.appender.routing.RoutingAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) AppenderControl(org.apache.logging.log4j.core.config.AppenderControl) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) IgniteLogger(org.apache.ignite.IgniteLogger) Logger(org.apache.logging.log4j.core.Logger) Field(java.lang.reflect.Field) RoutingAppender(org.apache.logging.log4j.core.appender.routing.RoutingAppender) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Field (java.lang.reflect.Field)1 Map (java.util.Map)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 Appender (org.apache.logging.log4j.core.Appender)1 Logger (org.apache.logging.log4j.core.Logger)1 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)1 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)1 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)1 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)1 AppenderControl (org.apache.logging.log4j.core.config.AppenderControl)1 Nullable (org.jetbrains.annotations.Nullable)1