Search in sources :

Example 1 with AppenderThresholdNotSupported

use of com.haulmont.cuba.core.sys.logging.AppenderThresholdNotSupported in project cuba by cuba-platform.

the class LogControlImpl method getAppenderThreshold.

@Override
public Level getAppenderThreshold(String appenderName) throws AppenderThresholdNotSupported {
    for (Map.Entry<String, Appender> entry : getAllAppenders().entrySet()) {
        if (entry.getKey().equals(appenderName)) {
            Appender appender = entry.getValue();
            for (Object filter : appender.getCopyOfAttachedFiltersList()) {
                if (filter instanceof ThresholdFilter) {
                    try {
                        Field field = filter.getClass().getDeclaredField("level");
                        field.setAccessible(true);
                        return (Level) field.get(filter);
                    } catch (NoSuchFieldException | IllegalAccessException e) {
                        log.error("Error getting appender " + appenderName + " level", e);
                        throw new AppenderThresholdNotSupported(appenderName);
                    }
                }
            }
        }
    }
    throw new AppenderThresholdNotSupported(appenderName);
}
Also used : Appender(ch.qos.logback.core.Appender) ThresholdFilter(ch.qos.logback.classic.filter.ThresholdFilter) Field(java.lang.reflect.Field) Level(ch.qos.logback.classic.Level) AppenderThresholdNotSupported(com.haulmont.cuba.core.sys.logging.AppenderThresholdNotSupported)

Aggregations

Level (ch.qos.logback.classic.Level)1 ThresholdFilter (ch.qos.logback.classic.filter.ThresholdFilter)1 Appender (ch.qos.logback.core.Appender)1 AppenderThresholdNotSupported (com.haulmont.cuba.core.sys.logging.AppenderThresholdNotSupported)1 Field (java.lang.reflect.Field)1