本文整理汇总了Java中ch.qos.logback.core.rolling.RollingFileAppender.setAppend方法的典型用法代码示例。如果您正苦于以下问题:Java RollingFileAppender.setAppend方法的具体用法?Java RollingFileAppender.setAppend怎么用?Java RollingFileAppender.setAppend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.core.rolling.RollingFileAppender
的用法示例。
在下文中一共展示了RollingFileAppender.setAppend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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.setParent(appender);
rolling.setFileNamePattern(new File(getLogPath(), fileName).getAbsolutePath() + ".%d{yyyy-MM-dd}");
rolling.setContext(loggerContext);
rolling.start();
appender.setRollingPolicy(rolling);
PatternLayout layout = new PatternLayout();
layout.setPattern(pattern);
layout.setContext(loggerContext);
layout.start();
appender.setLayout(layout);
// 启动
appender.start();
return appender;
}
示例4: 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);
PatternLayout layout = new PatternLayout();
layout.setContext(loggerContext);
layout.setPattern(pattern);
layout.start();
appender.setLayout(layout);
// 启动
appender.start();
return appender;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: 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;
}
示例12: 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);
}
示例13: DefaultTransactionLogHandler
import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
public DefaultTransactionLogHandler(final DefaultTransactionLogHandlerConfig logConfig,
final ObjectMapper mapper) {
final LoggerContext loggerContext = (LoggerContext) LoggerFactory
.getILoggerFactory();
final PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
patternLayoutEncoder
.setPattern("%date{\"yyyy-MM-dd HH:mm:ss.SSS z\",UTC} %msg%n");
patternLayoutEncoder.setContext(loggerContext);
patternLayoutEncoder.start();
final RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
fileAppender.setContext(loggerContext);
fileAppender.setAppend(true);
fileAppender.setEncoder(patternLayoutEncoder);
fileAppender.setPrudent(false);
fileAppender.setFile(logConfig.getTransactionLogFile());
final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();
rollingPolicy.setFileNamePattern(logConfig
.getTransactionLogFileRotationPattern());
rollingPolicy.setMaxHistory(logConfig.getMaxTransactionLogFileVersions());
rollingPolicy.setCleanHistoryOnStart(false);
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(fileAppender);
rollingPolicy.start();
fileAppender.setRollingPolicy(rollingPolicy);
fileAppender.setTriggeringPolicy(rollingPolicy);
fileAppender.start();
final ch.qos.logback.classic.Logger logBackLogger = (ch.qos.logback.classic.Logger) transactionLog;
logBackLogger.detachAndStopAllAppenders();
logBackLogger.addAppender(fileAppender);
logBackLogger.setLevel(Level.INFO);
logBackLogger.setAdditive(false);
this.writer = mapper.writer().without(
SerializationFeature.INDENT_OUTPUT);
}
示例14: getFileAppender
import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
/**
* Creates the file appender for the logger with a custom logging policy
* (RollingFileAppender with max size of 1 MB and up to 3 backups)
* @param logFile the file to log into
* @return the FileAppender for the specified File and current logging
* context
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
protected static FileAppender getFileAppender(File logFile) {
// init rolling file appender
RollingFileAppender rfAppender = new RollingFileAppender();
rfAppender.setContext(lc);
rfAppender.setFile(logFile.getAbsolutePath());
rfAppender.setAppend(true);
// rolling policy: keep up to 3 rollover-files with postfix .%i.log
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(lc);
rollingPolicy.setParent(rfAppender);
rollingPolicy.setFileNamePattern(logFileName + ".%i.log");
rollingPolicy.setMinIndex(1);
rollingPolicy.setMaxIndex(3);
rollingPolicy.start();
// rollover after logfixe exceeds 1MB
SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy();
triggeringPolicy.setMaxFileSize(FileSize.valueOf("1mb"));
triggeringPolicy.start();
// layout of the log entries
Encoder encoder = getDefaultEncoder();
// apply settings and start appender
rfAppender.setEncoder(encoder);
rfAppender.setRollingPolicy(rollingPolicy);
rfAppender.setTriggeringPolicy(triggeringPolicy);
rfAppender.start();
return rfAppender;
}
示例15: PhialLogger
import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
/**
* 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);
}