當前位置: 首頁>>代碼示例>>Java>>正文


Java PatternLayoutEncoder類代碼示例

本文整理匯總了Java中ch.qos.logback.classic.encoder.PatternLayoutEncoder的典型用法代碼示例。如果您正苦於以下問題:Java PatternLayoutEncoder類的具體用法?Java PatternLayoutEncoder怎麽用?Java PatternLayoutEncoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PatternLayoutEncoder類屬於ch.qos.logback.classic.encoder包,在下文中一共展示了PatternLayoutEncoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fileAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config,
		String logFile) {
	RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>();
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	String logPattern = this.patterns.getProperty("file", FILE_LOG_PATTERN);
	encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
	appender.setEncoder(encoder);
	config.start(encoder);

	appender.setFile(logFile);

	FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
	rollingPolicy.setFileNamePattern(logFile + ".%i");
	appender.setRollingPolicy(rollingPolicy);
	rollingPolicy.setParent(appender);
	config.start(rollingPolicy);

	SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
	triggeringPolicy.setMaxFileSize("10MB");
	appender.setTriggeringPolicy(triggeringPolicy);
	config.start(triggeringPolicy);

	config.appender("FILE", appender);
	return appender;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:26,代碼來源:DefaultLogbackConfiguration.java

示例2: WebSocketLogAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
public WebSocketLogAppender(String sessionId) {
    // deliberately NOT the com.intuit form else will pick up all those
    // this is supposed to isolate user-session s
    this.sessionId = sessionId;
    logger = (Logger) LoggerFactory.getLogger(sessionId);
    sb = new StringBuilder();
    setName("karate-web");
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    setContext(lc);
    encoder = new PatternLayoutEncoder();
    encoder.setPattern("%d{HH:mm:ss.SSS} %-5level - %msg%n");
    encoder.setContext(context);
    encoder.start();
    start();
    logger.addAppender(this);
    logger.setLevel(Level.DEBUG);
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:18,代碼來源:WebSocketLogAppender.java

示例3: configureInMemoryLogging

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
private static void configureInMemoryLogging() {
    org.slf4j.Logger rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    Logger logbackRootLogger = (Logger) rootLogger;
    logbackRootLogger.setLevel(Level.INFO);

    OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<>();
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder ple = new PatternLayoutEncoder();
    ple.setPattern("[%date] [%level] [%logger{10}] %msg%n");
    ple.setContext(lc);
    ple.start();
    try {
        ple.init(bos);
    } catch (IOException e) {
    }
    appender.setContext(lc);
    appender.setOutputStream(bos);
    appender.setName("buffered");
    appender.setEncoder(ple);
    appender.start();

    logbackRootLogger.detachAppender("console");
    logbackRootLogger.addAppender(appender);
    logbackRootLogger.setAdditive(true);
}
 
開發者ID:spinscale,項目名稱:maxcube-java,代碼行數:26,代碼來源:Cli.java

示例4: log

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
@Test
public void log() throws Exception {
    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    LoggerContext context = logger.getLoggerContext();
    context.reset();

    Map<String, String> ruleRegistry = (Map) context.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
    if (ruleRegistry == null) {
        ruleRegistry = new HashMap<String, String>();
        context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, ruleRegistry);
    }
    ruleRegistry.put("ex1L", OnelineThrowableProxyConverter.class.getCanonicalName());

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%d{yyyy/MM/dd HH:mm:ss:SSS}\\t%-5level\\t%msg\\t%ex1L");
    encoder.start();

    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(context);
    appender.setEncoder(encoder);
    appender.start();
    logger.addAppender(appender);

    logger.error("error", new RuntimeException("foo"));
}
 
開發者ID:roundrop,項目名稱:logback-oneline-converter,代碼行數:27,代碼來源:OnelineThrowableProxyConverterTest.java

示例5: log

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
@Test
public void log() throws Exception {
    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    LoggerContext context = logger.getLoggerContext();
    context.reset();

    Map<String, String> ruleRegistry = (Map) context.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
    if (ruleRegistry == null) {
        ruleRegistry = new HashMap<String, String>();
        context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, ruleRegistry);
    }
    ruleRegistry.put("xEx1L", OnelineExtendedThrowableProxyConverter.class.getCanonicalName());

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%d{yyyy/MM/dd HH:mm:ss:SSS}\\t%-5level\\t%msg\\t%xEx1L");
    encoder.start();

    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(context);
    appender.setEncoder(encoder);
    appender.start();
    logger.addAppender(appender);

    logger.error("error", new RuntimeException());
}
 
開發者ID:roundrop,項目名稱:logback-oneline-converter,代碼行數:27,代碼來源:OnelineExtendedThrowableProxyConverterTest.java

示例6: addAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
/**
 * Start a specific file logging, typically for the processing of a given book.
 *
 * @param name      appender name (typically the book radix)
 * @param logFolder target folder where the log file is to be written
 */
public static void addAppender (String name,
                                Path logFolder)
{
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
            Logger.ROOT_LOGGER_NAME);
    FileAppender fileAppender = new FileAppender();
    PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
    fileAppender.setName(name);
    fileAppender.setContext(loggerContext);
    fileAppender.setAppend(false);

    String now = new SimpleDateFormat("yyyyMMdd'T'HHmm").format(new Date());
    Path logFile = logFolder.resolve(name + "-" + now + ".log");
    fileAppender.setFile(logFile.toAbsolutePath().toString());
    fileEncoder.setContext(loggerContext);
    fileEncoder.setPattern("%date %level [%X{BOOK}%X{SHEET}] %25file:%-4line | %msg%n%ex");
    fileEncoder.start();
    fileAppender.setEncoder(fileEncoder);
    fileAppender.start();
    root.addAppender(fileAppender);
}
 
開發者ID:Audiveris,項目名稱:audiveris,代碼行數:29,代碼來源:LogUtil.java

示例7: addFileAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
/**
 * Add a specific appender meant for FILE.
 */
public static void addFileAppender ()
{
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
            Logger.ROOT_LOGGER_NAME);
    FileAppender fileAppender = new FileAppender();
    PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
    fileAppender.setName("FILE");
    fileAppender.setContext(loggerContext);
    fileAppender.setAppend(false);

    String now = new SimpleDateFormat("yyyyMMdd'T'HHmmss").format(new Date());
    Path logPath = WellKnowns.LOG_FOLDER.resolve(now + ".log").toAbsolutePath();
    fileAppender.setFile(logPath.toString());
    fileEncoder.setContext(loggerContext);
    fileEncoder.setPattern("%date %-5level [%X{BOOK}%X{SHEET}] %25replace(%file){'\\.java$',''} %-4line | %msg%n%ex");
    fileEncoder.start();
    fileAppender.setEncoder(fileEncoder);
    fileAppender.start();
    root.addAppender(fileAppender);

    System.out.println("LogUtil. Logging to " + logPath);
}
 
開發者ID:Audiveris,項目名稱:audiveris,代碼行數:27,代碼來源:LogUtil.java

示例8: buildFileAppender

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
public FileAppender<ILoggingEvent> buildFileAppender(LoggerContext context, String file) {
  FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
  fileAppender.setFile(file);
  fileAppender.setContext(context);
  fileAppender.setPrudent(true);

  PatternLayoutEncoder encoder = new PatternLayoutEncoder();
  encoder.setContext(context);
  encoder.setPattern(primaryConfiguration.getLoggingPattern().or(baseConfiguration.getLoggingPattern()).or(JavaUtils.LOGBACK_LOGGING_PATTERN));
  encoder.start();

  fileAppender.setEncoder(encoder);
  fileAppender.start();

  return fileAppender;
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:17,代碼來源:SingularityRunnerBaseLogging.java

示例9: logToFile

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
static void logToFile(Parameters parameters) {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder ple = new PatternLayoutEncoder();

    ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
    ple.setContext(lc);
    ple.start();
    FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
    fileAppender.setFile(parameters.getWorkingDirectory() + "/jlineup.log");
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();

    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    logger.addAppender(fileAppender);
    logger.setLevel(Level.DEBUG);
}
 
開發者ID:otto-de,項目名稱:jlineup,代碼行數:18,代碼來源:Util.java

示例10: configure

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
public static void configure(KonkerLoggerContext lc) {
    StatusManager sm = lc.getStatusManager();
    if(sm != null) {
        sm.add(new InfoStatus("Setting up default configuration.", lc));
    }

    ConsoleAppender ca = new ConsoleAppender();
    ca.setContext(lc);
    ca.setName("console");
    PatternLayoutEncoder pl = new PatternLayoutEncoder();
    pl.setContext(lc);
    pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
    pl.start();
    ca.setEncoder(pl);
    ca.start();
    KonkerLogger rootLogger = lc.getLogger("ROOT");
    rootLogger.addAppender(ca);
}
 
開發者ID:KonkerLabs,項目名稱:konker-platform,代碼行數:19,代碼來源:KonkerLoggerBasicConfigurator.java

示例11: build

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
@Override
public Appender<ILoggingEvent> build(LoggerContext context, String s, Layout<ILoggingEvent> layout) {
    Preconditions.checkNotNull(context);
    WiretapAppender appender = new WiretapAppender();

    final PatternLayoutEncoder patternEncoder = new PatternLayoutEncoder();
    patternEncoder.setContext(context);
    patternEncoder.setPattern("%-5p [%thread] [%d] %c: %m%n%rEx");
    patternEncoder.start();

    appender.setContext(context);
    appender.setName("wiretap-appender");
    appender.setEncoder(patternEncoder);

    addThresholdFilter(appender, threshold);
    appender.start();

    return wrapAsync(appender);
}
 
開發者ID:Quiq,項目名稱:dropwizard-wiretap,代碼行數:20,代碼來源:WiretapAppenderFactory.java

示例12: setupLogging

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
private static void setupLogging(TestConfig testConfig) {
    val logFile = new java.io.File(testConfig.getTestLogPath());
    if (logFile.delete()) {
        TestLogger.log("Main", "Deleted log file %s.", logFile.getAbsolutePath());
    }

    // Configure slf4j to not log anything (console or whatever). This interferes with the console interaction.
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.getLoggerList().get(0).detachAndStopAllAppenders();

    val fa = new FileAppender<ILoggingEvent>();
    fa.setContext(context);
    fa.setName("selftest");
    fa.setFile(logFile.getAbsolutePath());

    val encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %level - %msg%n");
    encoder.start();
    fa.setEncoder(encoder);
    fa.start();

    context.getLoggerList().get(0).addAppender(fa);
    context.getLoggerList().get(0).setLevel(Level.INFO);
    //context.reset();
}
 
開發者ID:pravega,項目名稱:pravega,代碼行數:27,代碼來源:SelfTestRunner.java

示例13: configure

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
/**
 * Initializes the logger and the requested log level.
 *
 * @param level Logging level threshold
 */
@SuppressWarnings("unchecked")
public static void configure(final Level level) {
    final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(level);

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(root.getLoggerContext());
    encoder.setPattern("%msg%n");
    encoder.start();

    Iterator<Appender<ILoggingEvent>> iterator = root.iteratorForAppenders();

    while (iterator.hasNext()) {
        Appender<ILoggingEvent> appender = iterator.next();
        if (appender instanceof OutputStreamAppender) {
            ((OutputStreamAppender) appender).setEncoder(encoder);
        }
        appender.stop();
        appender.start();
    }
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-lifecycle-cli,代碼行數:27,代碼來源:LoggingConfigurer.java

示例14: setupConsole

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
private void setupConsole(LogFixtureBuilder builder) {
  drillLogger = (Logger)LoggerFactory.getLogger(DRILL_PACKAGE_NAME);
  if (drillLogger.getAppender("STDOUT") != null) {
    return;
  }
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
  ple = new PatternLayoutEncoder();
  ple.setPattern(builder.consoleFormat);
  ple.setContext(lc);
  ple.start();

  appender = new ConsoleAppender<>( );
  appender.setContext(lc);
  appender.setName("Console");
  appender.setEncoder( ple );
  appender.start();

  Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
  root.addAppender(appender);
  drillLogger.addAppender(appender);
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:22,代碼來源:LogFixture.java

示例15: createLogger

import ch.qos.logback.classic.encoder.PatternLayoutEncoder; //導入依賴的package包/類
private Logger createLogger(File logFile) {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    ch.qos.logback.classic.Logger log = loggers.get();
    log.setAdditive(false);

    FileAppender fileAppender = new FileAppender();
    fileAppender.setContext(context);
    fileAppender.setName(Thread.currentThread().getName());
    fileAppender.setFile(logFile.getAbsolutePath());

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern(LOG_PATTERN);
    encoder.start();

    fileAppender.setEncoder(encoder);
    fileAppender.start();

    log.detachAndStopAllAppenders();
    log.addAppender(fileAppender);

    return log;
}
 
開發者ID:dmart28,項目名稱:gcplot,代碼行數:24,代碼來源:DefaultLogsProcessorService.java


注:本文中的ch.qos.logback.classic.encoder.PatternLayoutEncoder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。