use of ch.qos.logback.classic.spi.ILoggingEvent in project sonarqube by SonarSource.
the class AppLoggingTest method root_logger_only_writes_to_console_with_formatting_when_running_from_sonar_script.
@Test
public void root_logger_only_writes_to_console_with_formatting_when_running_from_sonar_script() {
emulateRunFromSonarScript();
LoggerContext ctx = underTest.configure();
Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) rootLogger.getAppender("APP_CONSOLE");
verifyAppFormattedLogEncoder(consoleAppender.getEncoder());
assertThat(rootLogger.iteratorForAppenders()).hasSize(1);
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project sonarqube by SonarSource.
the class LogbackHelper method newConsoleAppender.
/**
* Creates a new {@link ConsoleAppender} to {@code System.out} with the specified name and log pattern.
*
* @see #buildLogPattern(RootLoggerConfig)
*/
public ConsoleAppender<ILoggingEvent> newConsoleAppender(Context loggerContext, String name, String logPattern) {
PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder();
consoleEncoder.setContext(loggerContext);
consoleEncoder.setPattern(logPattern);
consoleEncoder.start();
ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.setContext(loggerContext);
consoleAppender.setEncoder(consoleEncoder);
consoleAppender.setName(name);
consoleAppender.setTarget("System.out");
consoleAppender.start();
return consoleAppender;
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project sonarqube by SonarSource.
the class SearchLoggingTest method log_to_es_file.
@Test
public void log_to_es_file() {
LoggerContext ctx = underTest.configure(props);
Logger root = ctx.getLogger(ROOT_LOGGER_NAME);
Appender<ILoggingEvent> appender = root.getAppender("file_es");
assertThat(appender).isInstanceOf(FileAppender.class);
FileAppender fileAppender = (FileAppender) appender;
assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "es.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 es[][%logger{20}] %msg%n");
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project jadx by skylot.
the class LogCollector method init.
private String init(Level filterLevel) {
StringBuilder sb = new StringBuilder();
int length = getLength();
for (int i = 0; i < length; i++) {
ILoggingEvent event = get(i);
if (event.getLevel().isGreaterOrEqual(filterLevel)) {
sb.append(layout.doLayout(event));
}
}
return sb.toString();
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project sakuli by ConSol.
the class LoggerInitializerTest method testInitLoggerContextFromIncludeFolder.
@Test
public void testInitLoggerContextFromIncludeFolder() throws Throwable {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger root = context.getLogger("root");
Logger sakuliLogger = context.getLogger("org.sakuli");
Appender<ILoggingEvent> stdout = root.getAppender("stdout");
Appender<ILoggingEvent> sakuliAppender = root.getAppender("sakuli");
//no log config in classpath
Assert.assertNull(stdout);
Assert.assertNull(sakuliAppender);
Assert.assertNotNull(sakuliLogger);
Assert.assertNotNull(root);
when(sakuliProperties.getConfigFolder()).thenReturn(Paths.get(BaseTest.SAKULI_HOME_FOLDER_PATH + SakuliProperties.CONFIG_FOLDER_APPEDER));
testling.initLoggerContext();
verify(testling).getConfigFileFromClasspath();
verify(testling).getConfigFile();
//verify root logger
context = (LoggerContext) LoggerFactory.getILoggerFactory();
root = context.getLogger("root");
sakuliLogger = context.getLogger("org.sakuli");
stdout = root.getAppender("stdout");
sakuliAppender = root.getAppender("sakuli");
Assert.assertNotNull(stdout);
Assert.assertNotNull(sakuliLogger);
Assert.assertNotNull(sakuliAppender);
Assert.assertNotNull(sakuliAppender);
}
Aggregations