当前位置: 首页>>代码示例>>Java>>正文


Java RollingFileAppender.setEncoder方法代码示例

本文整理汇总了Java中ch.qos.logback.core.rolling.RollingFileAppender.setEncoder方法的典型用法代码示例。如果您正苦于以下问题:Java RollingFileAppender.setEncoder方法的具体用法?Java RollingFileAppender.setEncoder怎么用?Java RollingFileAppender.setEncoder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.qos.logback.core.rolling.RollingFileAppender的用法示例。


在下文中一共展示了RollingFileAppender.setEncoder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fileAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的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: createRollingFileAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
protected FileAppender<ILoggingEvent> createRollingFileAppender(Encoder<ILoggingEvent> encoder,
                                                                LoggerContext context,
                                                                RollingPolicyFactory rollingPolicy) {

    RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
    appender.setFile(file);
    appender.setContext(context);
    appender.setEncoder(encoder);
    // Setup rolling policy
    RollingPolicy policy = rollingPolicy.createRollingPolicy(context);
    appender.setRollingPolicy(policy);
    policy.setParent(appender);
    // Setup triggering policy
    TriggeringPolicy<ILoggingEvent> triggeringPolicy = rollingPolicy.createTriggeringPolicy(context);
    if (triggeringPolicy != null) {
        appender.setTriggeringPolicy(triggeringPolicy);
        triggeringPolicy.start();
    }
    policy.start();
    appender.start();

    return appender;
}
 
开发者ID:bootique,项目名称:bootique-logback,代码行数:24,代码来源:FileAppenderFactory.java

示例3: getLogger

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
public Logger getLogger() {
    LoggerContext  context = (LoggerContext)LoggerFactory.getILoggerFactory();
    Logger rootLogger = context.getLogger("ROOT");
    rootLogger.detachAppender("console");

    // Just a simple pattern for outputting the messages, includes the ISO8601 formatted timestamp and marker.
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%msg");
    encoder.start();

    RollingFileAppender appender = new RollingFileAppender<>();
    appender.setContext(context);
    appender.setRollingPolicy(new ExternalRotateRollingPolicy());
    appender.getRollingPolicy().setParent(appender);
    appender.setFile(new File(folder.getRoot(), "log").getAbsolutePath());

    appender.setEncoder(encoder);
    appender.start();
    rootLogger.addAppender(appender);
    context.start();
    return rootLogger;

}
 
开发者ID:ezbake,项目名称:ezbake-common-java,代码行数:25,代码来源:TestExternalRotateRollingPolicy.java

示例4: buildAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
protected Appender buildAppender(String name, String fileName, String pattern) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setContext(loggerContext);
    rolling.setParent(appender);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd}");
    rolling.start();
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setContext(loggerContext);
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    layout.start();
    appender.setEncoder(layout);
    // 启动
    appender.start();
    return appender;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:25,代码来源:DynamicLogbackLogger.java

示例5: buildDailyMaxRollingAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
protected Appender buildDailyMaxRollingAppender(String name, String fileName, String pattern, int maxBackupIndex) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setContext(loggerContext);
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setContext(loggerContext);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd-HH}");
    rolling.setMaxHistory(maxBackupIndex);
    rolling.setParent(appender);
    rolling.start();
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setContext(loggerContext);
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    layout.start();
    appender.setEncoder(layout);
    // 启动
    appender.start();
    return appender;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:26,代码来源:DynamicLogbackLogger.java

示例6: buildAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
private Appender buildAppender(String name, String fileName, String pattern) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setParent(appender);
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd}");
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    appender.setEncoder(layout);
    // 启动
    appender.start();
    return appender;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:20,代码来源:DynamicLogbackLogger.java

示例7: buildDailyMaxRollingAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
private Appender buildDailyMaxRollingAppender(String name, String fileName, String pattern, int maxBackupIndex) {
    RollingFileAppender appender = new RollingFileAppender();
    appender.setName(name);
    appender.setAppend(true);
    appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());

    TimeBasedRollingPolicy rolling = new TimeBasedRollingPolicy();
    rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd-HH}");
    rolling.setMaxHistory(maxBackupIndex);
    rolling.setParent(appender);
    appender.setRollingPolicy(rolling);

    PatternLayoutEncoder layout = new PatternLayoutEncoder();
    layout.setPattern(pattern);
    layout.setCharset(Charset.forName(getEncoding()));
    appender.setEncoder(layout);
    // 启动
    appender.start();
    return appender;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:21,代码来源:DynamicLogbackLogger.java

示例8: addFileAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
public static void addFileAppender(String name, String logPattern, String filePath, int maxHistory) {
	RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
       fileAppender.setFile(filePath);
       fileAppender.setEncoder(getPatternLayoutEncoder(logPattern));
       fileAppender.setContext(loggerContext);
       fileAppender.setName(name);
       fileAppender.setAppend(true);
       
       // time based rolling policy
       TimeBasedRollingPolicy<ILoggingEvent> logFilePolicy = new TimeBasedRollingPolicy<>();
    logFilePolicy.setContext(loggerContext);
    logFilePolicy.setParent(fileAppender);
    logFilePolicy.setFileNamePattern(getDateBasedFileName(filePath));
    logFilePolicy.setMaxHistory(50);
    logFilePolicy.start();
    
    fileAppender.setRollingPolicy(logFilePolicy);
       fileAppender.start();

       registeredAppenders.put(name, fileAppender);
}
 
开发者ID:sangupta,项目名称:jerry-core,代码行数:22,代码来源:ApplicationLogger.java

示例9: getAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
private FileAppender<ILoggingEvent> getAppender(String pluginId) {
    File pluginLogFileLocation = pluginLogFile(pluginId);

    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<>();
    rollingFileAppender.setEncoder(LogHelper.encoder());
    rollingFileAppender.setContext(LogHelper.LOGGER_CONTEXT);
    rollingFileAppender.setFile(pluginLogFileLocation.getPath());
    rollingFileAppender.setName(rollingFileAppenderName(pluginId));

    LogHelper.rollingPolicyForAppender(
            rollingFileAppender,
            "5 MB",
            "20 MB",
            7
    );

    rollingFileAppender.start();
    return rollingFileAppender;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:20,代码来源:DefaultPluginLoggingService.java

示例10: rollingAppender

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
private RollingFileAppender<ILoggingEvent> rollingAppender(String file) throws IOException {
    RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<>();
    rollingFileAppender.setEncoder(LogHelper.encoder("%date{ISO8601} - %msg%n"));
    rollingFileAppender.setContext(LogHelper.LOGGER_CONTEXT);
    rollingFileAppender.setFile(getEffectiveLogDirectory(file));
    rollingFileAppender.setName(UUID.randomUUID().toString());

    LogHelper.rollingPolicyForAppender(
            rollingFileAppender,
            "5 MB",
            "20 MB",
            4
    );
    rollingFileAppender.start();
    return rollingFileAppender;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:17,代码来源:AgentOutputAppender.java

示例11: doInitializer

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
/**
 * Initializer logback
 * 
 * @param file
 * @param level
 * @param maxHistory
 */
private void doInitializer(String file, String level, int maxHistory) {
	LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
	Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
	rootLogger.detachAndStopAllAppenders();

	// appender
	RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
	fileAppender.setContext(loggerContext);
	fileAppender.setName("application");
	fileAppender.setFile(file);
	fileAppender.setAppend(true);

	// policy
	TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
	policy.setContext(loggerContext);
	policy.setMaxHistory(maxHistory);
	policy.setFileNamePattern(file + ".%d{yyyy-MM-dd}");
	policy.setParent(fileAppender);
	policy.start();
	fileAppender.setRollingPolicy(policy);

	// encoder
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	encoder.setContext(loggerContext);
	encoder.setPattern("%date [%thread] %-5level %logger (%file:%line\\) - %msg%n");
	encoder.start();
	fileAppender.setEncoder(encoder);
	
	fileAppender.start();

	rootLogger.addAppender(fileAppender);
	rootLogger.setLevel(Level.toLevel(level));
	rootLogger.setAdditive(false);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:42,代码来源:LogbackContainer.java

示例12: setupLogger

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
@Override
public void setupLogger() {
    String file = checkFile();
       LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
       Logger newLogger =loggerContext.getLogger("ROOT");
       //Remove all previously added appenders from this logger instance.
       newLogger.detachAndStopAllAppenders();
       //define appender
       RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>();
       //policy
       TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
       policy.setContext(loggerContext);
       policy.setMaxHistory(day);
       policy.setFileNamePattern(formateLogFile(file));
       policy.setParent(appender);
       policy.start();
       //encoder
       PatternLayoutEncoder encoder = new PatternLayoutEncoder();
       encoder.setContext(loggerContext);
       encoder.setPattern(formatePattern);
       encoder.start();
       //start appender
       appender.setRollingPolicy(policy);
       appender.setContext(loggerContext);
       appender.setEncoder(encoder);
       appender.setPrudent(true); //support that multiple JVMs can safely write to the same file.
       appender.start();
       newLogger.addAppender(appender);
       //setup level
       setLevel(newLogger);
       //remove the appenders that inherited 'ROOT'.
       newLogger.setAdditive(false);
}
 
开发者ID:DTStack,项目名称:jlogstash,代码行数:34,代码来源:LogbackComponent.java

示例13: doInitializer

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
/**
 * Initializer logback
 *
 * @param file       log file
 * @param level      log level
 * @param maxHistory max history
 */
private void doInitializer(String file, String level, int maxHistory) {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.detachAndStopAllAppenders();

    // appender
    RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<>();
    fileAppender.setContext(loggerContext);
    fileAppender.setName("application");
    fileAppender.setFile(file);
    fileAppender.setAppend(true);

    // policy
    TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<>();
    policy.setContext(loggerContext);
    policy.setMaxHistory(maxHistory);
    policy.setFileNamePattern(file + ".%d{yyyy-MM-dd}");
    policy.setParent(fileAppender);
    policy.start();
    fileAppender.setRollingPolicy(policy);

    // encoder
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%date [%thread] %-5level %logger (%file:%line\\) - %msg%n");
    encoder.start();
    fileAppender.setEncoder(encoder);

    fileAppender.start();

    rootLogger.addAppender(fileAppender);
    rootLogger.setLevel(Level.toLevel(level));
    rootLogger.setAdditive(false);
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:42,代码来源:LogbackContainer.java

示例14: createFlusher

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
public static Flusher createFlusher(String name, String dir, String file) {
        Preconditions.checkArgument(new File(dir).exists(), String.format("dir[%s] not exist", dir));

//        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        LoggerContext context = new LoggerContext();
        Logger logger = context.getLogger(name);
        logger.setAdditive(false);

        RollingFileAppender rollingFileAppender = new RollingFileAppender();
        rollingFileAppender.setContext(context);
        rollingFileAppender.setName(name + "_appender");

        rollingFileAppender.setFile(dir + File.separator + file + ".dat");
        rollingFileAppender.setAppend(true);

        TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
        rollingPolicy.setFileNamePattern(dir + File.separator + file + ".%d{yyyy-MM-dd_HH}.dat");
        rollingPolicy.setParent(rollingFileAppender);
        rollingPolicy.setContext(context);
        rollingPolicy.start();

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

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


        logger.addAppender(rollingFileAppender);

        return new Flusher(logger);
    }
 
开发者ID:alain898,项目名称:distributed-search-cache,代码行数:36,代码来源:PersistUtils.java

示例15: buildLoggerContext

import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
static LoggerContext buildLoggerContext(String stamp, String filename,
    boolean safetyMode) {
  LoggerContext loggerContext = new LoggerContext();

  RollingFileAppender<ILoggingEvent> rfa = new RollingFileAppender<ILoggingEvent>();
  PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
  patternLayout.setPattern(stamp + " %5p - %-50m%n");
  patternLayout.setContext(loggerContext);
  patternLayout.start();

  rfa.setEncoder(patternLayout);
  
  rfa.setAppend(true);
  rfa.setPrudent(safetyMode);
  rfa.setContext(loggerContext);

  TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
  
  tbrp.setContext(loggerContext);
  tbrp.setFileNamePattern(filename+"-%d{"+DATE_PATTERN+"}.log");
  tbrp.setParent(rfa);
  tbrp.start();

  rfa.setRollingPolicy(tbrp);

  
  rfa.start();

  ch.qos.logback.classic.Logger root = loggerContext
      .getLogger(Logger.ROOT_LOGGER_NAME);
  root.addAppender(rfa);

  return loggerContext;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:35,代码来源:SafeModeRollingFileAppender.java


注:本文中的ch.qos.logback.core.rolling.RollingFileAppender.setEncoder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。