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 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());
}
}
}
}
}
use of ch.qos.logback.core.Appender in project sling by apache.
the class LogbackManager method determineLoggerState.
// ~ ----------------------------------------------WebConsole Support
public LoggerStateContext determineLoggerState() {
final List<Logger> loggers = getLoggerContext().getLoggerList();
final LoggerStateContext ctx = new LoggerStateContext(loggers);
//2. Other means - Configured via Logback config or any other means
for (LogConfig lc : logConfigManager.getLogConfigs()) {
for (String category : lc.getCategories()) {
ctx.osgiConfiguredLoggers.put(category, lc);
}
}
for (Logger logger : loggers) {
boolean hasOnlySlingRollingAppenders = true;
Iterator<Appender<ILoggingEvent>> itr = logger.iteratorForAppenders();
while (itr.hasNext()) {
Appender<ILoggingEvent> a = itr.next();
if (a.getName() != null && !ctx.appenders.containsKey(a.getName())) {
ctx.appenders.put(a.getName(), a);
}
if (!(a instanceof SlingRollingFileAppender)) {
hasOnlySlingRollingAppenders = false;
}
}
if (logger.getLevel() == null) {
continue;
}
boolean configuredViaOSGiConfig = ctx.osgiConfiguredLoggers.containsKey(logger.getName());
if (!configuredViaOSGiConfig || (configuredViaOSGiConfig && !hasOnlySlingRollingAppenders)) {
ctx.nonOSgiConfiguredLoggers.add(logger);
}
}
return ctx;
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationConfigInstallerTest method testRunASE.
/**
* Tests the {@link ApplicationConfigInstaller#run()} method for the case
* where an ApplicationServiceException is thrown by appService.addApplication(..)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunASE() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
FeaturesService featuresService = mock(FeaturesService.class);
ApplicationService testAppService = mock(ApplicationServiceImpl.class);
doThrow(new ApplicationServiceException()).when(testAppService).startApplication(anyString());
URL fileURL = this.getClass().getResource("/" + GOOD_FILE);
ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), testAppService, featuresService, START_FEATURE, STOP_FEATURE);
configInstaller.run();
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(RUN_ASE_EX);
}
}));
}
Aggregations