use of ch.qos.logback.core.FileAppender in project gocd by gocd.
the class DefaultPluginLoggingServiceTest method assertPluginLogFile.
private void assertPluginLogFile(String pluginId, String expectedPluginLogFileName) {
SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
DefaultPluginLoggingService loggingService = new DefaultPluginLoggingService(systemEnvironment);
loggingService.debug(pluginId, "some-logger-name", "message");
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("plugin." + pluginId);
ArrayList<Appender<ILoggingEvent>> appenders = new ArrayList<>();
logger.iteratorForAppenders().forEachRemaining(new Consumer<Appender<ILoggingEvent>>() {
@Override
public void accept(Appender<ILoggingEvent> iLoggingEventAppender) {
appenders.add(iLoggingEventAppender);
}
});
String loggingDirectory = loggingService.getCurrentLogDirectory();
assertThat(appenders.size()).isEqualTo(1);
assertThat(new File(((FileAppender) appenders.get(0)).rawFileProperty())).isEqualTo(new File(loggingDirectory, expectedPluginLogFileName));
}
use of ch.qos.logback.core.FileAppender in project sonarqube by SonarSource.
the class WebServerProcessLoggingTest method log_for_cluster_changes_layout_in_file_and_console.
@Test
public void log_for_cluster_changes_layout_in_file_and_console() {
props.set("sonar.cluster.enabled", "true");
props.set("sonar.cluster.node.name", "my-node");
LoggerContext ctx = underTest.configure(props);
Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
FileAppender fileAppender = (FileAppender) root.getAppender("file_web");
PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level my-node web[%X{HTTP_REQUEST_ID}][%logger{20}] %msg%n");
Logger startup = ctx.getLogger("startup");
ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) startup.getAppender("CONSOLE");
PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) consoleAppender.getEncoder();
assertThat(patternEncoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level my-node app[][%logger{20}] %msg%n");
}
use of ch.qos.logback.core.FileAppender in project sonarqube by SonarSource.
the class LogbackHelperTest method createRollingPolicy_size.
@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);
}
use of ch.qos.logback.core.FileAppender in project sonarqube by SonarSource.
the class CeProcessLoggingTest method log_to_ce_file.
@Test
public void log_to_ce_file() {
LoggerContext ctx = underTest.configure(props);
Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
Appender<ILoggingEvent> appender = root.getAppender("file_ce");
assertThat(appender).isInstanceOf(FileAppender.class);
FileAppender fileAppender = (FileAppender) appender;
assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "ce.log").getAbsolutePath());
assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level ce[%X{ceTaskUuid}][%logger{20}] %msg%n");
}
use of ch.qos.logback.core.FileAppender in project sonarqube by SonarSource.
the class AppLoggingTest method verifySonarLogFileAppender.
private void verifySonarLogFileAppender(Appender<ILoggingEvent> appender) {
assertThat(appender).isInstanceOf(FileAppender.class);
FileAppender fileAppender = (FileAppender) appender;
assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "sonar.log").getAbsolutePath());
verifyAppFormattedLogEncoder(fileAppender.getEncoder());
}
Aggregations