Java 类ch.qos.logback.classic.html.HTMLLayout 实例源码

项目:bartleby    文件:SMTPAppender_SubethaSMTPTest.java   
private Layout<ILoggingEvent> buildHTMLLayout(LoggerContext lc) {
  HTMLLayout layout = new HTMLLayout();
  layout.setContext(lc);
  // layout.setFileHeader(HEADER);
  layout.setPattern("%level%class%msg");
  // layout.setFileFooter(FOOTER);
  layout.start();
  return layout;
}
项目:bartleby    文件:SMTPAppender_GreenTest.java   
private Layout<ILoggingEvent> buildHTMLLayout() {
  HTMLLayout layout = new HTMLLayout();
  layout.setContext(loggerContext);
  layout.setPattern("%level%class%msg");
  layout.start();
  return layout;
}
项目:Phial    文件:PhialLogger.java   
/**
 * Creates Logger that will write logs in html file using slf4j and logback.
 * The logs will be included in Phial Attachment
 *
 * @param context application context
 */
public PhialLogger(Context context) {
    logDir = createLogDir(context);
    clearOldLogs(logDir);

    final String logDirectory = logDir.getAbsolutePath();
    // reset the default context (which may already have been initialized)
    // since we want to reconfigure it
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    loggerContext.reset();

    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<>();
    rollingFileAppender.setContext(loggerContext);
    rollingFileAppender.setAppend(true);
    rollingFileAppender.setFile(logDirectory + "/" + LOG_PREFIX + "-latest.html");

    SizeAndTimeBasedFNATP<ILoggingEvent> fileNamingPolicy = new SizeAndTimeBasedFNATP<>();
    fileNamingPolicy.setContext(loggerContext);
    fileNamingPolicy.setMaxFileSize(MAX_FILE_SIZE);

    TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<>();
    rollingPolicy.setContext(loggerContext);
    rollingPolicy.setFileNamePattern(logDirectory + "/" + LOG_PREFIX + HISTORY_FILE_NAME_PATTERN);
    rollingPolicy.setMaxHistory(5);
    rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(fileNamingPolicy);
    rollingPolicy.setParent(rollingFileAppender);  // parent and context required!
    rollingPolicy.start();

    HTMLLayout htmlLayout = new HTMLLayout();
    htmlLayout.setContext(loggerContext);
    htmlLayout.setPattern(PATTERN);
    htmlLayout.start();

    LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
    encoder.setContext(loggerContext);
    encoder.setLayout(htmlLayout);
    encoder.start();

    rollingFileAppender.setRollingPolicy(rollingPolicy);
    rollingFileAppender.setEncoder(encoder);
    rollingFileAppender.start();

    // add the newly created appenders to the root logger;
    // qualify Logger to disambiguate from org.slf4j.Logger
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.DEBUG);
    root.addAppender(rollingFileAppender);
    // print any status messages (warnings, etc) encountered in logback config
    StatusPrinter.print(loggerContext);
}
项目:uavstack    文件:LogBackHookProxy.java   
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);

        }
    }