use of ch.qos.logback.core.ConsoleAppender 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.ConsoleAppender in project sonarqube by SonarSource.
the class CeProcessLoggingTest method startup_logger_prints_to_only_to_system_out.
@Test
public void startup_logger_prints_to_only_to_system_out() {
LoggerContext ctx = underTest.configure(props);
Logger startup = ctx.getLogger("startup");
assertThat(startup.isAdditive()).isFalse();
Appender appender = startup.getAppender("CONSOLE");
assertThat(appender).isInstanceOf(ConsoleAppender.class);
ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) appender;
assertThat(consoleAppender.getTarget()).isEqualTo("System.out");
assertThat(consoleAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) consoleAppender.getEncoder();
assertThat(patternEncoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level app[][%logger{20}] %msg%n");
}
use of ch.qos.logback.core.ConsoleAppender 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()).toIterable().hasSize(1);
}
use of ch.qos.logback.core.ConsoleAppender in project engineblock by engineblock.
the class ScenarioLogger method start.
public ScenarioLogger start() {
if (!loggerDir.exists()) {
if (!loggerDir.mkdirs()) {
throw new RuntimeException("Unable to create logger directory:" + loggerDir.getPath());
}
}
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
// List<LoggerContextListener> copyOfListenerList = loggerContext.getCopyOfListenerList();
ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
ca.setContext(loggerContext);
PatternLayoutEncoder ple = new PatternLayoutEncoder();
// ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setContext(loggerContext);
ple.start();
String scenarioLog = loggerDir.getPath() + File.separator + scenario.getName() + ".log";
scenarioLog = scenarioLog.replaceAll("\\s", "_");
FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
fileAppender.setFile(scenarioLog);
fileAppender.setEncoder(ple);
fileAppender.setContext(loggerContext);
System.err.println("Logging to " + scenarioLog);
fileAppender.start();
Logger logger = (Logger) LoggerFactory.getLogger("ROOT");
logger.addAppender(fileAppender);
logLevelOverrides.forEach((loggerName, loggingLevel) -> {
logger.debug("Overriding log level for " + loggerName + " to " + loggingLevel);
Logger toOverride = (Logger) LoggerFactory.getLogger(loggerName);
toOverride.setLevel(loggingLevel);
toOverride.debug("Log level was set to " + loggingLevel + " by engineblock CLI option.");
});
logger.setLevel(logLevel);
logger.setAdditive(true);
/* set to true if root should log too */
purgeOldFiles(logger);
return this;
}
use of ch.qos.logback.core.ConsoleAppender in project engineblock by engineblock.
the class ConsoleLogging method enableConsoleLogging.
public static void enableConsoleLogging(Level level, String loggingPattern) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
// List<LoggerContextListener> copyOfListenerList = loggerContext.getCopyOfListenerList();
ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
ca.setContext(loggerContext);
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern(loggingPattern);
ple.setContext(loggerContext);
ple.start();
ca.setEncoder(ple);
LevelFilter<ILoggingEvent> levelFilter = new LevelFilter<>(level);
levelFilter.start();
ca.addFilter(levelFilter);
ca.start();
Logger root = loggerContext.getLogger("ROOT");
root.addAppender(ca);
root.setLevel(Level.TRACE);
}
Aggregations