本文整理了Java中ch.qos.logback.core.rolling.RollingFileAppender.getRollingPolicy
方法的一些代码示例,展示了RollingFileAppender.getRollingPolicy
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RollingFileAppender.getRollingPolicy
方法的具体详情如下:
包路径:ch.qos.logback.core.rolling.RollingFileAppender
类名称:RollingFileAppender
方法名:getRollingPolicy
暂无
代码示例来源:origin: SonarSource/sonarqube
@Test
public void createRollingPolicy_size() throws Exception {
props.set("sonar.log.rollingPolicy", "size:1MB");
props.set("sonar.log.maxFiles", "20");
LoggerContext ctx = underTest.getRootContext();
LogbackHelper.RollingPolicy policy = underTest.createRollingPolicy(ctx, props, "sonar");
Appender appender = policy.createAppender("SONAR_FILE");
assertThat(appender).isInstanceOf(RollingFileAppender.class);
// max 20 files of 1Mb
RollingFileAppender fileAppender = (RollingFileAppender) appender;
FixedWindowRollingPolicy rollingPolicy = (FixedWindowRollingPolicy) fileAppender.getRollingPolicy();
assertThat(rollingPolicy.getMaxIndex()).isEqualTo(20);
assertThat(rollingPolicy.getFileNamePattern()).endsWith("sonar.%i.log");
SizeBasedTriggeringPolicy triggeringPolicy = (SizeBasedTriggeringPolicy) fileAppender.getTriggeringPolicy();
FileSize maxFileSize = (FileSize) FieldUtils.readField(triggeringPolicy, "maxFileSize", true);
assertThat(maxFileSize.getSize()).isEqualTo(1024L * 1024);
}
代码示例来源:origin: stackoverflow.com
import ch.qos.logback.classic.Logger;
import ch.qos.logback.core.rolling.RollingFileAppender;
import org.slf4j.LoggerFactory;
public class Main {
public static void main(String[] args) {
Logger logger = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
RollingFileAppender appender=(RollingFileAppender)logger.getAppender("DateRollingFileAppender");
System.out.println(appender.getRollingPolicy().getActiveFileName());
}
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-config
public void setAppender(Appender<?> appender) {
super.setAppender(appender);
if (appender instanceof RollingFileAppender) {
RollingPolicy rp = ((RollingFileAppender<?>)appender).getRollingPolicy();
if (rp instanceof TimeBasedRollingPolicy) {
fileNamePattern = ((TimeBasedRollingPolicy)rp).getFileNamePattern();
}
else {
throw new UnsupportedOperationException("Must be TimeBasedRollingPolicy!");
}
}
else {
throw new RuntimeException(
"MultipleFileLogReader appender must be an instance of RollingFileAppender!");
}
}
代码示例来源:origin: org.openrdf.sesame/sesame-config
public void setAppender(Appender<?> appender) {
super.setAppender(appender);
if (appender instanceof RollingFileAppender) {
RollingPolicy rp = ((RollingFileAppender<?>)appender).getRollingPolicy();
if (rp instanceof TimeBasedRollingPolicy) {
fileNamePattern = ((TimeBasedRollingPolicy)rp).getFileNamePattern();
}
else {
throw new UnsupportedOperationException("Must be TimeBasedRollingPolicy!");
}
}
else {
throw new RuntimeException(
"MultipleFileLogReader appender must be an instance of RollingFileAppender!");
}
}
代码示例来源:origin: stackoverflow.com
import org.apache.log4j.Logger;
import org.apache.log4j.rolling.RollingFileAppender;
import org.apache.log4j.rolling.TimeBasedRollingPolicy;
...
private static void afunction(String pTheNewFileName) {
Logger logger = Logger.getLogger("TheLoggerName");
RollingFileAppender rfappender = (RollingFileAppender) logger.getAppender("TheAppenderName");
TimeBasedRollingPolicy timeBasedRollingPolicy = (TimeBasedRollingPolicy) rfappender.getRollingPolicy();
timeBasedRollingPolicy.setFileNamePattern("newfilename%d{yyyy-MM}");
timeBasedRollingPolicy.activateOptions();
rfappender.activateOptions();
}
代码示例来源:origin: stackoverflow.com
private static final String LOG4J_ROLLING_FILE_NAME_TOKEN = "Launcher";
/*
* Change the name of the the log file as configured through log4j.xml
* by replacing the placeholder file name token ("Launcher") with the
* a new "actionName".
*/
private static void log4jConfig(String actionName) {
org.apache.log4j.Logger rootLogger = LogManager.getRootLogger();
RollingFileAppender fileAppender = (RollingFileAppender)rootLogger.getAppender("fileAppender");
// <param name="FileNamePattern" value="/var/log/Launcher.log.%d{yyyy-MM-dd}.gz"/>
String currentLogFile = fileAppender.getFile();
String newLogPattern = currentLogFile.replace(LOG4J_ROLLING_FILE_NAME_TOKEN, actionName);
fileAppender.setFile(newLogPattern);
TimeBasedRollingPolicy timeBasedRollingPolicy = (TimeBasedRollingPolicy) fileAppender.getRollingPolicy();
String fileNamePattern = timeBasedRollingPolicy.getFileNamePattern();
String newFileNamePattern = fileNamePattern.replace(LOG4J_ROLLING_FILE_NAME_TOKEN, actionName);;
timeBasedRollingPolicy.setFileNamePattern(newFileNamePattern);
timeBasedRollingPolicy.activateOptions();
fileAppender.activateOptions();
LOG.info(" Redirected launcher log output to log pattern: " + newFileNamePattern);
}
代码示例来源:origin: org.opendaylight.controller/logback-config
app.setEncoderPattern(encoder.getPattern());
app.setFileName(rollingApp.getFile());
if (rollingApp.getRollingPolicy() instanceof FixedWindowRollingPolicy) {
FixedWindowRollingPolicy rollingPolicy = (FixedWindowRollingPolicy) rollingApp
.getRollingPolicy();
app.setMaxIndex(rollingPolicy.getMaxIndex());
app.setMinIndex(rollingPolicy.getMinIndex());
app.setFileNamePattern(rollingPolicy.getFileNamePattern());
app.setRollingPolicyType("FixedWindowRollingPolicy");
} else if (rollingApp.getRollingPolicy() instanceof TimeBasedRollingPolicy<?>) {
TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = (TimeBasedRollingPolicy<ILoggingEvent>) rollingApp.getRollingPolicy();
app.setRollingPolicyType("TimeBasedRollingPolicy");
app.setFileNamePattern(rollingPolicy.getFileNamePattern());
内容来源于网络,如有侵权,请联系作者删除!