use of ch.qos.logback.core.rolling.RollingFileAppender 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.RollingFileAppender in project spring-boot by spring-projects.
the class DefaultLogbackConfiguration method fileAppender.
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config, String logFile) {
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
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);
setRollingPolicy(appender, config, logFile);
setMaxFileSize(appender, config);
config.appender("FILE", appender);
return appender;
}
use of ch.qos.logback.core.rolling.RollingFileAppender in project cdap-ingest by caskdata.
the class FileTailerMetricsProcessor method run.
@Override
public void run() {
RollingFileAppender appender = null;
ch.qos.logback.classic.Logger logger = initLogger("metricsLogger");
try {
createDirs(stateDirPath);
createFile(stateDirPath + "/" + metricsFileName);
appender = initAppender(stateDirPath.getAbsolutePath(), metricsFileName);
writeMetricsHeader(logger, appender);
while (isRunning()) {
for (long i = 0; i < metricsSleepInterval; i += SLEEP_INTERVAL) {
Thread.sleep(SLEEP_INTERVAL);
if (!isRunning()) {
throw new InterruptedException();
}
}
String currentDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
writeMetrics(logger, appender, currentDate);
resetMetrics();
}
} catch (InterruptedException e) {
LOG.debug("Metric Processor was interrupted");
} finally {
if (appender != null) {
String currentDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
writeMetrics(logger, appender, currentDate);
appender.stop();
}
}
LOG.info("Metrics Processor stopped");
}
use of ch.qos.logback.core.rolling.RollingFileAppender in project cdap-ingest by caskdata.
the class FileTailerIT method getTimeLogger.
private Logger getTimeLogger(String file) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setName("File Tailer IT");
fileAppender.setContext(loggerContext);
fileAppender.setFile(file);
fileAppender.setAppend(true);
TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(fileAppender);
rollingPolicy.setFileNamePattern(file + "%d{yyyy-MM-dd_HH-mm}");
rollingPolicy.start();
fileAppender.setRollingPolicy(rollingPolicy);
PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
layoutEncoder.setContext(loggerContext);
layoutEncoder.setPattern("%msg%n");
layoutEncoder.start();
fileAppender.setEncoder(layoutEncoder);
fileAppender.start();
// configures the logger
Logger logger = loggerContext.getLogger(FileTailerIT.class.getName() + "time");
logger.setLevel(Level.DEBUG);
logger.addAppender(fileAppender);
return logger;
}
use of ch.qos.logback.core.rolling.RollingFileAppender in project cdap-ingest by caskdata.
the class TailerLogUtils method getSizeLogger.
public static Logger getSizeLogger(String file, String fileSize) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setContext(loggerContext);
fileAppender.setFile(file);
fileAppender.setAppend(true);
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setFileNamePattern(file + "%i");
rollingPolicy.setParent(fileAppender);
rollingPolicy.start();
rollingPolicy.setMaxIndex(100);
fileAppender.setRollingPolicy(rollingPolicy);
SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy();
triggeringPolicy.setContext(loggerContext);
triggeringPolicy.setMaxFileSize(fileSize);
triggeringPolicy.start();
fileAppender.setTriggeringPolicy(triggeringPolicy);
PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
layoutEncoder.setContext(loggerContext);
layoutEncoder.setPattern("[%d %-5p %c{1}] %msg%n");
layoutEncoder.start();
fileAppender.setEncoder(layoutEncoder);
fileAppender.start();
// configures logger
Logger rootLogger = loggerContext.getLogger(BaseTailerTest.class.getName() + "size");
rootLogger.setLevel(Level.DEBUG);
rootLogger.addAppender(fileAppender);
return rootLogger;
}
Aggregations