use of ch.qos.logback.classic.spi.ILoggingEvent in project netty by netty.
the class SingleThreadEventLoopTest method testRegistrationAfterShutdown.
@Test(timeout = 10000)
@SuppressWarnings("deprecation")
public void testRegistrationAfterShutdown() throws Exception {
loopA.shutdown();
// Disable logging temporarily.
Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
List<Appender<ILoggingEvent>> appenders = new ArrayList<Appender<ILoggingEvent>>();
for (Iterator<Appender<ILoggingEvent>> i = root.iteratorForAppenders(); i.hasNext(); ) {
Appender<ILoggingEvent> a = i.next();
appenders.add(a);
root.detachAppender(a);
}
try {
ChannelFuture f = loopA.register(new LocalChannel());
f.awaitUninterruptibly();
assertFalse(f.isSuccess());
assertThat(f.cause(), is(instanceOf(RejectedExecutionException.class)));
assertFalse(f.channel().isOpen());
} finally {
for (Appender<ILoggingEvent> a : appenders) {
root.addAppender(a);
}
}
}
use of ch.qos.logback.classic.spi.ILoggingEvent in project sonarqube by SonarSource.
the class AppLogging method configureConsole.
/**
* Creates a non additive logger dedicated to printing message as is (ie. assuming they are already formatted).
*
* It creates a dedicated appender to the System.out which applies no formatting the logs it receives.
*/
private void configureConsole(LoggerContext loggerContext) {
ConsoleAppender<ILoggingEvent> consoleAppender = helper.newConsoleAppender(loggerContext, CONSOLE_PLAIN_APPENDER, "%msg%n");
Logger consoleLogger = loggerContext.getLogger(CONSOLE_LOGGER);
consoleLogger.setAdditive(false);
consoleLogger.addAppender(consoleAppender);
}
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");
}
Aggregations