本文整理汇总了Java中ch.qos.logback.core.rolling.RollingFileAppender.setFile方法的典型用法代码示例。如果您正苦于以下问题:Java RollingFileAppender.setFile方法的具体用法?Java RollingFileAppender.setFile怎么用?Java RollingFileAppender.setFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.core.rolling.RollingFileAppender
的用法示例。
在下文中一共展示了RollingFileAppender.setFile方法的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;
}
示例2: 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;
}
示例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.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;
}
示例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);
PatternLayoutEncoder layout = new PatternLayoutEncoder();
layout.setContext(loggerContext);
layout.setPattern(pattern);
layout.setCharset(Charset.forName(getEncoding()));
layout.start();
appender.setEncoder(layout);
// 启动
appender.start();
return appender;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: setUp
import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
final RollingFileAppender<LoggingEvent> fileAppender = new RollingFileAppender<>();
fileAppender.setFile("application.log");
final TimeBasedRollingPolicy<LoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<>();
_context = new LoggerContext();
_triggeringPolicy = new SizeAndRandomizedTimeBasedFNATP<>(_wrappedPolicy);
rollingPolicy.setContext(_context);
rollingPolicy.setFileNamePattern("application-%d{yyyy-MM-dd_HH}.log");
rollingPolicy.setParent(fileAppender);
rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(_triggeringPolicy);
rollingPolicy.start();
}
示例11: 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);
}
示例12: 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;
}
示例13: 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;
}
示例14: configureFileLogging
import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
private static OutputStreamAppender<ILoggingEvent> configureFileLogging(File logFile, LoggerContext loggerContext) {
RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
rollingFileAppender.setFile(logFile.getAbsolutePath());
rollingFileAppender.setName("com.documents4j.logger.client.file");
rollingFileAppender.setContext(loggerContext);
FixedWindowRollingPolicy fixedWindowRollingPolicy = new FixedWindowRollingPolicy();
fixedWindowRollingPolicy.setFileNamePattern(logFile.getAbsolutePath() + ".%i.gz");
fixedWindowRollingPolicy.setMaxIndex(LogDescription.MAXIMUM_LOG_HISTORY_INDEX);
fixedWindowRollingPolicy.setContext(loggerContext);
fixedWindowRollingPolicy.setParent(rollingFileAppender);
SizeBasedTriggeringPolicy<ILoggingEvent> sizeBasedTriggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
sizeBasedTriggeringPolicy.setMaxFileSize(LogDescription.MAXIMUM_LOG_FILE_SIZE);
sizeBasedTriggeringPolicy.setContext(loggerContext);
rollingFileAppender.setRollingPolicy(fixedWindowRollingPolicy);
rollingFileAppender.setTriggeringPolicy(sizeBasedTriggeringPolicy);
sizeBasedTriggeringPolicy.start();
fixedWindowRollingPolicy.start();
System.out.println("Logging: The log is written to " + logFile);
return rollingFileAppender;
}
示例15: configureFileLogging
import ch.qos.logback.core.rolling.RollingFileAppender; //导入方法依赖的package包/类
private static OutputStreamAppender<ILoggingEvent> configureFileLogging(File logFile, LoggerContext loggerContext) {
RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();
rollingFileAppender.setFile(logFile.getAbsolutePath());
rollingFileAppender.setName("com.documents4j.logger.server.file");
rollingFileAppender.setContext(loggerContext);
FixedWindowRollingPolicy fixedWindowRollingPolicy = new FixedWindowRollingPolicy();
fixedWindowRollingPolicy.setFileNamePattern(logFile.getAbsolutePath() + ".%i.gz");
fixedWindowRollingPolicy.setMaxIndex(LogDescription.MAXIMUM_LOG_HISTORY_INDEX);
fixedWindowRollingPolicy.setContext(loggerContext);
fixedWindowRollingPolicy.setParent(rollingFileAppender);
SizeBasedTriggeringPolicy<ILoggingEvent> sizeBasedTriggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
sizeBasedTriggeringPolicy.setMaxFileSize(LogDescription.MAXIMUM_LOG_FILE_SIZE);
sizeBasedTriggeringPolicy.setContext(loggerContext);
rollingFileAppender.setRollingPolicy(fixedWindowRollingPolicy);
rollingFileAppender.setTriggeringPolicy(sizeBasedTriggeringPolicy);
sizeBasedTriggeringPolicy.start();
fixedWindowRollingPolicy.start();
System.out.println("Logging: The log is written to " + logFile);
return rollingFileAppender;
}