use of ch.qos.logback.core.Appender in project sonarqube by SonarSource.
the class CeProcessLoggingTest method do_not_log_to_console.
@Test
public void do_not_log_to_console() {
LoggerContext ctx = underTest.configure(props);
Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
Appender appender = root.getAppender("CONSOLE");
assertThat(appender).isNull();
}
use of ch.qos.logback.core.Appender in project sonarqube by SonarSource.
the class LogbackHelperTest method createRollingPolicy_none.
@Test
public void createRollingPolicy_none() {
props.set("sonar.log.rollingPolicy", "none");
LoggerContext ctx = underTest.getRootContext();
LogbackHelper.RollingPolicy policy = underTest.createRollingPolicy(ctx, props, "sonar");
Appender appender = policy.createAppender("SONAR_FILE");
assertThat(appender).isNotInstanceOf(RollingFileAppender.class).isInstanceOf(FileAppender.class);
}
use of ch.qos.logback.core.Appender in project sonarqube by SonarSource.
the class LogbackHelperTest method createRollingPolicy_size.
@Test
public void createRollingPolicy_size() {
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();
assertThat(triggeringPolicy.getMaxFileSize()).isEqualTo("1MB");
}
use of ch.qos.logback.core.Appender in project jackrabbit-oak by apache.
the class LogLevelModifier method finished.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void finished(Description description) {
for (Iterator<AppenderFilter> it = appenderFilters.iterator(); it.hasNext(); ) {
AppenderFilter appenderFilter = (AppenderFilter) it.next();
appenderFilter.finished();
}
for (Iterator<LoggerLevel> it = loggerLevels.iterator(); it.hasNext(); ) {
LoggerLevel loggerLevel = (LoggerLevel) it.next();
loggerLevel.finished();
}
for (Iterator<Appender> it = newAppenders.iterator(); it.hasNext(); ) {
Appender appender = it.next();
rootLogger().detachAppender(appender);
}
}
use of ch.qos.logback.core.Appender in project sling by apache.
the class LogConfigManager method onResetComplete.
@SuppressWarnings("unchecked")
@Override
public void onResetComplete(LoggerContext context) {
//The OSGi config based appenders are attached on reset complete as by that time Logback config
// would have been parsed and various appenders and logger configured. Now we use the OSGi config
// 1. If an appender with same name as one defined by OSGi config is found then it takes precedence
// 2. If no existing appender is found then we create one use that
Map<String, Appender<ILoggingEvent>> appendersByName = new HashMap<String, Appender<ILoggingEvent>>();
Map<String, Appender<ILoggingEvent>> configuredAppenders = (Map<String, Appender<ILoggingEvent>>) context.getObject(ActionConst.APPENDER_BAG);
if (configuredAppenders == null) {
configuredAppenders = Collections.emptyMap();
}
Map<Appender, LoggerSpecificEncoder> encoders = new HashMap<Appender, LoggerSpecificEncoder>();
for (LogConfig config : getLogConfigs()) {
Appender<ILoggingEvent> appender = null;
if (config.isAppenderDefined()) {
LogWriter lw = config.getLogWriter();
final String appenderName = lw.getAppenderName();
appender = appendersByName.get(appenderName);
if (appender == null) {
appender = configuredAppenders.get(appenderName);
if (appender != null) {
contextUtil.addInfo("Found overriding configuration for appender " + appenderName + " in Logback config. OSGi config would be ignored");
}
}
if (appender == null) {
LoggerSpecificEncoder encoder = new LoggerSpecificEncoder(getDefaultLayout());
appender = lw.createAppender(loggerContext, encoder);
encoders.put(appender, encoder);
appendersByName.put(appenderName, appender);
}
if (encoders.containsKey(appender)) {
encoders.get(appender).addLogConfig(config);
}
}
for (String category : config.getCategories()) {
ch.qos.logback.classic.Logger logger = loggerContext.getLogger(category);
if (config.isResetToDefault()) {
logger.setLevel(null);
//Reset additivity
logger.setAdditive(true);
} else {
logger.setLevel(config.getLogLevel());
if (appender != null) {
logger.setAdditive(config.isAdditive());
logger.addAppender(appender);
contextUtil.addInfo("Registering appender " + appender.getName() + "(" + appender.getClass() + ") with logger " + logger.getName());
}
}
}
}
}
Aggregations