use of ch.qos.logback.core.rolling.TimeBasedRollingPolicy in project midpoint by Evolveum.
the class TestLoggingConfiguration method test110SetMaxHistory.
// MID-5674
@Test
public void test110SetMaxHistory() throws Exception {
// GIVEN
Task task = taskManager.createTaskInstance(TestLoggingConfiguration.class.getName() + ".test101EnableBasicAudit");
OperationResult result = task.getResult();
// Setup
PrismObject<SystemConfigurationType> systemConfiguration = PrismTestUtil.parseObject(AbstractInitializedModelIntegrationTest.SYSTEM_CONFIGURATION_FILE);
LoggingConfigurationType logging = systemConfiguration.asObjectable().getLogging();
applyTestLoggingConfig(logging);
((FileAppenderConfigurationType) logging.getAppender().get(0)).setMaxHistory(100);
Collection<ObjectDelta<? extends ObjectType>> deltas = cast(prismContext.deltaFor(SystemConfigurationType.class).item(SystemConfigurationType.F_LOGGING).replace(logging.asPrismContainerValue().clone()).asObjectDeltas(AbstractInitializedModelIntegrationTest.SYSTEM_CONFIGURATION_OID));
// WHEN
modelService.executeChanges(deltas, null, task, result);
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME);
assertNotNull("No logger", logger);
Iterator<Appender<ILoggingEvent>> appenderIterator = logger.iteratorForAppenders();
RollingFileAppender<ILoggingEvent> fileAppender = null;
while (appenderIterator.hasNext()) {
Appender<ILoggingEvent> appender = appenderIterator.next();
System.out.println("Appender: " + appender);
if (appender instanceof RollingFileAppender) {
fileAppender = (RollingFileAppender<ILoggingEvent>) appender;
break;
}
}
assertNotNull("No file appender", fileAppender);
RollingPolicy rollingPolicy = fileAppender.getRollingPolicy();
System.out.println("Rolling policy = " + rollingPolicy);
assertTrue("Wrong type of rolling policy", rollingPolicy instanceof TimeBasedRollingPolicy);
TimeBasedRollingPolicy<?> timeBasedRollingPolicy = (TimeBasedRollingPolicy<?>) rollingPolicy;
assertEquals("Wrong maxHistory", 100, timeBasedRollingPolicy.getMaxHistory());
}
use of ch.qos.logback.core.rolling.TimeBasedRollingPolicy in project sonarqube by SonarSource.
the class LogbackHelperTest method createRollingPolicy_defaults.
@Test
public void createRollingPolicy_defaults() {
LoggerContext ctx = underTest.getRootContext();
LogbackHelper.RollingPolicy policy = underTest.createRollingPolicy(ctx, props, "sonar");
FileAppender appender = policy.createAppender("SONAR_FILE");
assertThat(appender).isInstanceOf(RollingFileAppender.class);
// max 5 daily files
RollingFileAppender fileAppender = (RollingFileAppender) appender;
TimeBasedRollingPolicy triggeringPolicy = (TimeBasedRollingPolicy) fileAppender.getTriggeringPolicy();
assertThat(triggeringPolicy.getMaxHistory()).isEqualTo(7);
assertThat(triggeringPolicy.getFileNamePattern()).endsWith("sonar.%d{yyyy-MM-dd}.log");
}
use of ch.qos.logback.core.rolling.TimeBasedRollingPolicy in project jmxtrans by jmxtrans.
the class TimeBasedRollingKeyOutWriter method initRollingPolicy.
protected RollingPolicy initRollingPolicy(String fileName, int maxBackupFiles, String maxFileSize) {
SizeAndTimeBasedFNATP sizeTimeBasedPolicy = new SizeAndTimeBasedFNATP();
// the max file size before rolling to a new file
sizeTimeBasedPolicy.setMaxFileSize(maxFileSize);
sizeTimeBasedPolicy.setContext(loggerContext);
TimeBasedRollingPolicy policy = new TimeBasedRollingPolicy();
// set the filename pattern
policy.setFileNamePattern(fileName);
// the maximum number of backup files to keep around
policy.setMaxHistory(maxBackupFiles);
policy.setTimeBasedFileNamingAndTriggeringPolicy(sizeTimeBasedPolicy);
policy.setContext(loggerContext);
return policy;
}
use of ch.qos.logback.core.rolling.TimeBasedRollingPolicy in project sling by apache.
the class LogWriter method createAppender.
public Appender<ILoggingEvent> createAppender(final Context context, final Encoder<ILoggingEvent> encoder) {
SlingContextUtil ctxUtil = new SlingContextUtil(context, this);
OutputStreamAppender<ILoggingEvent> appender;
if (FILE_NAME_CONSOLE.equals(fileName)) {
appender = new ConsoleAppender<ILoggingEvent>();
appender.setName(FILE_NAME_CONSOLE);
} else {
ctxUtil.addInfo("Configuring appender " + getFileName());
SlingRollingFileAppender<ILoggingEvent> rollingAppender = new SlingRollingFileAppender<ILoggingEvent>();
rollingAppender.setAppend(true);
rollingAppender.setFile(getFileName());
Matcher sizeMatcher = SIZE_SPEC.matcher(getLogRotation());
if (sizeMatcher.matches()) {
// group 1 is the base size and is an integer number
final long baseSize = Long.parseLong(sizeMatcher.group(1));
// this will take the final size value
final long maxSize;
// group 2 is optional and is the size spec. If not null it is
// at least one character long and the first character is enough
// for use to know (the second is of no use here)
final String factorString = sizeMatcher.group(2);
if (factorString == null) {
// no factor define, hence no multiplication
maxSize = baseSize;
} else {
switch(factorString.charAt(0)) {
case 'k':
case 'K':
maxSize = baseSize * FACTOR_KB;
break;
case 'm':
case 'M':
maxSize = baseSize * FACTOR_MB;
break;
case 'g':
case 'G':
maxSize = baseSize * FACTOR_GB;
break;
default:
// we don't really expect this according to the
// pattern
maxSize = baseSize;
}
}
SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
triggeringPolicy.setMaxFileSize(String.valueOf(maxSize));
triggeringPolicy.setContext(context);
triggeringPolicy.start();
rollingAppender.setTriggeringPolicy(triggeringPolicy);
FixedWindowRollingPolicy pol = new FixedWindowRollingPolicy();
pol.setMinIndex(1);
pol.setMaxIndex(getLogNumber());
pol.setFileNamePattern(getFileName() + "%i");
pol.setContext(context);
pol.setParent(rollingAppender);
pol.start();
rollingAppender.setRollingPolicy(pol);
} else {
TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
String fileNamePattern = createFileNamePattern(getFileName(), getLogRotation());
policy.setFileNamePattern(fileNamePattern);
policy.setMaxHistory(getLogNumber());
policy.setContext(context);
policy.setParent(rollingAppender);
policy.start();
rollingAppender.setTriggeringPolicy(policy);
ctxUtil.addInfo("Configured TimeBasedRollingPolicy with pattern " + fileNamePattern);
}
rollingAppender.setLogWriter(this);
rollingAppender.setName(getAppenderName());
appender = rollingAppender;
}
if (bufferedLogging && encoder instanceof LayoutWrappingEncoder) {
((LayoutWrappingEncoder) encoder).setImmediateFlush(false);
ctxUtil.addInfo("Setting immediateFlush to false");
} else {
ctxUtil.addInfo("immediateFlush property not modified. Defaults to true");
}
appender.setContext(context);
appender.setEncoder(encoder);
appender.start();
ctxUtil.addInfo("Completed configuring appender with name " + getFileName());
return appender;
}
use of ch.qos.logback.core.rolling.TimeBasedRollingPolicy in project coffeenet-starter by coffeenet.
the class CoffeeNetLoggingAutoConfiguration method rollingFileAppender.
private RollingFileAppender<ILoggingEvent> rollingFileAppender(LoggerContext loggerContext) {
RollingFileAppender<ILoggingEvent> rfAppender = new RollingFileAppender<>();
rfAppender.setName(COFFEENET_FILE_APPENDER);
rfAppender.setContext(loggerContext);
rfAppender.setFile(coffeeNetLoggingFileProperties.getFile());
// TimeBasedRollingPolicy
TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(rfAppender);
rollingPolicy.setFileNamePattern(coffeeNetLoggingFileProperties.getFileNamePattern());
rollingPolicy.setMaxHistory(coffeeNetLoggingFileProperties.getMaxHistory());
rollingPolicy.start();
rfAppender.setRollingPolicy(rollingPolicy);
// PatternLayoutEncoder
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern(coffeeNetLoggingFileProperties.getPattern());
encoder.start();
rfAppender.setEncoder(encoder);
rfAppender.start();
return rfAppender;
}
Aggregations