Search in sources :

Example 1 with TTLLLayout

use of ch.qos.logback.classic.layout.TTLLLayout in project uavstack by uavorg.

the class LogBackHookProxy method figureoutLogConfiguration.

private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {
    Iterator<Appender<ILoggingEvent>> appenders = Logger.iteratorForAppenders();
    while (appenders != null && appenders.hasNext()) {
        LogProfileInfo logProfileInfo = new LogProfileInfo();
        if (appid != null) {
            logProfileInfo.setAppId(appid);
        }
        logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);
        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put(LogProfileInfo.ENGINE, "logback");
        Appender<ILoggingEvent> appender = appenders.next();
        if (!(appender instanceof FileAppender<?>)) {
            continue;
        }
        FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) appender;
        @SuppressWarnings("rawtypes") LayoutWrappingEncoder encoder = (LayoutWrappingEncoder) fileAppender.getEncoder();
        Layout<?> layout = encoder.getLayout();
        if (null != layout) {
            if (layout instanceof PatternLayout) {
                PatternLayout patternLayout = (PatternLayout) encoder.getLayout();
                attributes.put(LogProfileInfo.PATTERN, patternLayout.getPattern());
            } else if (layout instanceof HTMLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "HTMLLayout");
            } else if (layout instanceof XMLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "XMLLayout");
            } else if (layout instanceof TTLLLayout) {
                attributes.put(LogProfileInfo.PATTERN, "TTCCLayout");
            }
        }
        logProfileInfo.setFilePath(fileAppender.getFile());
        logProfileInfo.setAttributes(attributes);
        list.add(logProfileInfo);
    }
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) HashMap(java.util.HashMap) HTMLLayout(ch.qos.logback.classic.html.HTMLLayout) PatternLayout(ch.qos.logback.classic.PatternLayout) TTLLLayout(ch.qos.logback.classic.layout.TTLLLayout) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogProfileInfo(com.creditease.uav.profiling.handlers.log.LogProfileInfo) XMLLayout(ch.qos.logback.classic.log4j.XMLLayout) LayoutWrappingEncoder(ch.qos.logback.core.encoder.LayoutWrappingEncoder)

Example 2 with TTLLLayout

use of ch.qos.logback.classic.layout.TTLLLayout in project grakn by graknlabs.

the class CoreLogback method configure.

public void configure(LoggerContext logContext, CoreConfig.Log logConfig) {
    // all appenders use the same layout
    LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
    encoder.setContext(logContext);
    // "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
    TTLLLayout layout = new TTLLLayout();
    layout.setContext(logContext);
    layout.start();
    encoder.setLayout(layout);
    Map<String, Appender<ILoggingEvent>> appenders = new HashMap<>();
    logConfig.output().outputs().forEach((name, outputType) -> appenders.put(name, appender(name, logContext, encoder, layout, outputType)));
    configureRootLogger(logConfig.logger().defaultLogger(), logContext, appenders);
    logConfig.logger().filteredLoggers().values().forEach(l -> configureLogger(l, logContext, appenders));
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) Appender(ch.qos.logback.core.Appender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) HashMap(java.util.HashMap) TTLLLayout(ch.qos.logback.classic.layout.TTLLLayout) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LayoutWrappingEncoder(ch.qos.logback.core.encoder.LayoutWrappingEncoder)

Aggregations

TTLLLayout (ch.qos.logback.classic.layout.TTLLLayout)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 Appender (ch.qos.logback.core.Appender)2 LayoutWrappingEncoder (ch.qos.logback.core.encoder.LayoutWrappingEncoder)2 HashMap (java.util.HashMap)2 PatternLayout (ch.qos.logback.classic.PatternLayout)1 HTMLLayout (ch.qos.logback.classic.html.HTMLLayout)1 XMLLayout (ch.qos.logback.classic.log4j.XMLLayout)1 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)1 FileAppender (ch.qos.logback.core.FileAppender)1 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)1 LogProfileInfo (com.creditease.uav.profiling.handlers.log.LogProfileInfo)1