ch.qos.logback.core.status.Status Java Examples

The following examples show how to use ch.qos.logback.core.status.Status. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogbackLoggingSystem.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadConfiguration(LoggingInitializationContext initializationContext, String location, LogFile logFile) {
	super.loadConfiguration(initializationContext, location, logFile);
	LoggerContext loggerContext = getLoggerContext();
	stopAndReset(loggerContext);
	try {
		configureByResourceUrl(initializationContext, loggerContext, ResourceUtils.getURL(location));
	} catch (Exception ex) {
		throw new IllegalStateException("Could not initialize Logback logging from " + location, ex);
	}
	List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList();
	StringBuilder errors = new StringBuilder();
	for (Status status : statuses) {
		if (status.getLevel() == Status.ERROR) {
			errors.append(errors.length() > 0 ? String.format("%n") : "");
			errors.append(status.toString());
		}
	}
	if (errors.length() > 0) {
		throw new IllegalStateException(String.format("Logback configuration error detected: %n%s", errors));
	}
}
 
Example #2
Source File: BrokerLoggerStatusListener.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public void addStatusEvent(Status status)
{
    Throwable throwable = status.getThrowable();
    if (status.getEffectiveLevel() == Status.ERROR
        && _errorClasses.stream().anyMatch(c -> c.isInstance(throwable)))
    {
        LOGGER.error("Unexpected error whilst trying to store log entry. Log messages could be lost.", throwable);
        if (_brokerLogger.getContextValue(Boolean.class, _contextFlag))
        {
            try
            {
                _brokerLogger.stopLogging();
                _systemConfig.getEventLogger().message(BrokerMessages.FATAL_ERROR(
                        String.format(
                                "Shutting down the broker because context variable '%s' is set and unexpected logging issue occurred: %s",
                                _contextFlag,
                                throwable.getMessage())));
            }
            finally
            {
                _systemConfig.closeAsync();
            }
        }
    }
}
 
Example #3
Source File: TestAppender.java    From aliyun-log-logback-appender with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void checkStatusList() {
    sleep();
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    StatusManager statusManager = lc.getStatusManager();
    List<Status> statusList = statusManager.getCopyOfStatusList();
    for (Status status : statusList) {
        int level = status.getLevel();
        assertNotEquals(status.getMessage(), Status.ERROR, level);
        assertNotEquals(status.getMessage(), Status.WARN, level);
    }
}
 
Example #4
Source File: BrokerLoggerStatusListenerTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddStatusEventForIOError()
{
    Status event = createEvent(new IOError(new IOException("Mocked: No disk space left")), Status.ERROR);
    _statusListener.addStatusEvent(event);

    verify(_systemConfig).closeAsync();
}
 
Example #5
Source File: BrokerLoggerStatusListenerTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddStatusEventForIOErrorWithFailOnLoggerIOErrorDisabled()
{
    Status event = createEvent(new IOError(new IOException("Mocked: No disk space left")), Status.ERROR);
    when(_fileLogger.getContextValue(Boolean.class, BrokerFileLogger.BROKER_FAIL_ON_LOGGER_IO_ERROR)).thenReturn(false);
    _statusListener.addStatusEvent(event);

    verify(_systemConfig, never()).closeAsync();
}
 
Example #6
Source File: BrokerLoggerStatusListenerTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddStatusEventForIOException()
{
    Status event = createEvent(new IOException("Mocked: No disk space left"), Status.ERROR);
    _statusListener.addStatusEvent(event);

    verify(_systemConfig).closeAsync();
}
 
Example #7
Source File: BrokerLoggerStatusListenerTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddStatusEventForIOExceptionReportedAsWarning()
{
    Status event = createEvent(new IOException("Mocked: No disk space left"), Status.WARN);
    _statusListener.addStatusEvent(event);

    verify(_systemConfig, never()).closeAsync();
}
 
Example #8
Source File: BrokerLoggerStatusListenerTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddStatusEventForNonIOException()
{
    Status event = createEvent(new RuntimeException("Mocked: No disk space left"), Status.ERROR);
    _statusListener.addStatusEvent(event);

    verify(_systemConfig, never()).closeAsync();
}
 
Example #9
Source File: BrokerLoggerStatusListenerTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private Status createEvent(Throwable throwable, int status)
{
    Status event = mock(Status.class);
    when(event.getThrowable()).thenReturn(throwable);
    when(event.getEffectiveLevel()).thenReturn(status);
    return event;
}
 
Example #10
Source File: RequestContextExportingAppenderTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@AfterEach
void tearDown() {
    final Logger logger = (Logger) LoggerFactory.getLogger(getClass());
    final StatusManager sm = rootLogger.getLoggerContext().getStatusManager();
    int count = 0;
    for (Status s : sm.getCopyOfStatusList()) {
        final int level = s.getEffectiveLevel();
        if (level == Status.INFO) {
            continue;
        }
        if (s.getMessage().contains(InternalLoggerFactory.class.getName())) {
            // Skip the warnings related with Netty.
            continue;
        }

        count++;
        switch (level) {
            case Status.WARN:
                if (s.getThrowable() != null) {
                    logger.warn(s.getMessage(), s.getThrowable());
                } else {
                    logger.warn(s.getMessage());
                }
                break;
            case Status.ERROR:
                if (s.getThrowable() != null) {
                    logger.warn(s.getMessage(), s.getThrowable());
                } else {
                    logger.warn(s.getMessage());
                }
                break;
        }
    }

    if (count > 0) {
        fail("Appender raised an exception.");
    }
}
 
Example #11
Source File: LogFileDefiner.java    From butterfly with MIT License 4 votes vote down vote up
@Override
public void addStatus(Status status) {
    // Nothing to be done here
}
 
Example #12
Source File: Logback1027WorkaroundTurboFilterTest.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
@Override
public void addStatus(final Status status)
{
    throw new UnsupportedOperationException();
}
 
Example #13
Source File: MetricsLogAppender.java    From pravega with Apache License 2.0 4 votes vote down vote up
@Override
public void addStatus(Status status) {
}
 
Example #14
Source File: KafkaAppenderIT.java    From logback-kafka-appender with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeLogSystemInit() throws IOException, InterruptedException {

    kafka = TestKafka.createTestKafka(1,1,1);

    loggerContext = new LoggerContext();
    loggerContext.putProperty("brokers.list", kafka.getBrokerList());
    loggerContext.getStatusManager().add(new StatusListener() {
        @Override
        public void addStatusEvent(Status status) {
            if (status.getEffectiveLevel() > Status.INFO) {
                System.err.println(status.toString());
                if (status.getThrowable() != null) {
                    collector.addError(status.getThrowable());
                } else {
                    collector.addError(new RuntimeException("StatusManager reported warning: "+status.toString()));
                }
            } else {
                System.out.println(status.toString());
            }
        }
    });
    loggerContext.putProperty("HOSTNAME","localhost");

    unit = new KafkaAppender<>();
    final PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
    patternLayoutEncoder.setPattern("%msg");
    patternLayoutEncoder.setContext(loggerContext);
    patternLayoutEncoder.setCharset(Charset.forName("UTF-8"));
    patternLayoutEncoder.start();
    unit.setEncoder(patternLayoutEncoder);
    unit.setTopic("logs");
    unit.setName("TestKafkaAppender");
    unit.setContext(loggerContext);
    unit.setKeyingStrategy(new NoKeyKeyingStrategy());
    unit.setDeliveryStrategy(new AsynchronousDeliveryStrategy());
    unit.addAppender(fallbackAppender);
    unit.addProducerConfigValue(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBrokerList());
    unit.addProducerConfigValue(ProducerConfig.ACKS_CONFIG, "1");
    unit.addProducerConfigValue(ProducerConfig.MAX_BLOCK_MS_CONFIG, "2000");
    unit.addProducerConfigValue(ProducerConfig.LINGER_MS_CONFIG, "100");
    unit.setPartition(0);
    unit.setDeliveryStrategy(new AsynchronousDeliveryStrategy());
    unit.addAppender(new AppenderBase<ILoggingEvent>() {
        @Override
        protected void append(ILoggingEvent eventObject) {
            fallbackLoggingEvents.add(eventObject);
        }
    });
}
 
Example #15
Source File: TestLogAppender.java    From specification-arg-resolver with Apache License 2.0 4 votes vote down vote up
@Override
public void addStatus(Status status) {
}