Java Code Examples for ch.qos.logback.core.read.ListAppender#start()
The following examples show how to use
ch.qos.logback.core.read.ListAppender#start() .
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: AbstractVirtualHostTest.java From qpid-broker-j with Apache License 2.0 | 7 votes |
private void assertActionProducesLogMessage(final Runnable action, final String loggerName, final Level logLevel, final String message) throws Exception { final CountDownLatch logMessageReceivedLatch = new CountDownLatch(1); ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); ListAppender<ILoggingEvent> appender = new ListAppender<>(); appender.addFilter(new Filter<ILoggingEvent>() { @Override public FilterReply decide(final ILoggingEvent event) { if (event.getLoggerName().equals(loggerName) && event.getLevel().equals(logLevel) && event.getFormattedMessage().contains(message)) { logMessageReceivedLatch.countDown(); } return FilterReply.NEUTRAL; } }); appender.setContext(rootLogger.getLoggerContext()); appender.start(); rootLogger.addAppender(appender); action.run(); assertTrue("Did not receive expected log message", logMessageReceivedLatch.await(2, TimeUnit.SECONDS)); }
Example 2
Source File: TestHttpNotificationServiceSSL.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testStartNotificationSucceedsNoKeystorePasswd() throws ParserConfigurationException, SAXException, IOException { Logger notificationServiceLogger = (Logger) LoggerFactory.getLogger(NotificationServiceManager.class); ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); listAppender.start(); notificationServiceLogger.addAppender(listAppender); String configFileOutput = CONFIGURATION_FILE_TEXT_NO_KEYSTORE_PASSWORD.replace("${test.server}", String.valueOf(mockWebServer.url("/"))); IOUtil.writeText(configFileOutput, new File(tempConfigFilePath)); NotificationServiceManager notificationServiceManager = new NotificationServiceManager(); notificationServiceManager.setMaxNotificationAttempts(1); notificationServiceManager.loadNotificationServices(new File(tempConfigFilePath)); List<ILoggingEvent> logsList = listAppender.list; boolean notificationServiceFailed = false; for (ILoggingEvent logMessage : logsList) { if (logMessage.getFormattedMessage().contains("is not valid for the following reasons")) { notificationServiceFailed = true; } } assertFalse(notificationServiceFailed); }
Example 3
Source File: TestHttpNotificationServiceSSL.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testStartNotificationSucceedsNoKeyPasswd() throws ParserConfigurationException, SAXException, IOException { Logger notificationServiceLogger = (Logger) LoggerFactory.getLogger(NotificationServiceManager.class); ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); listAppender.start(); notificationServiceLogger.addAppender(listAppender); String configFileOutput = CONFIGURATION_FILE_TEXT_NO_KEY_PASSWORD.replace("${test.server}", String.valueOf(mockWebServer.url("/"))); IOUtil.writeText(configFileOutput, new File(tempConfigFilePath)); NotificationServiceManager notificationServiceManager = new NotificationServiceManager(); notificationServiceManager.setMaxNotificationAttempts(1); notificationServiceManager.loadNotificationServices(new File(tempConfigFilePath)); List<ILoggingEvent> logsList = listAppender.list; boolean notificationServiceFailed = false; for (ILoggingEvent logMessage : logsList) { if (logMessage.getFormattedMessage().contains("is not valid for the following reasons")) { notificationServiceFailed = true; } } assertFalse(notificationServiceFailed); }
Example 4
Source File: TestHttpNotificationServiceSSL.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testStartNotificationFailsBlankKeystorePasswdCorrectKeypasswd() throws ParserConfigurationException, SAXException, IOException { Logger notificationServiceLogger = (Logger) LoggerFactory.getLogger(NotificationServiceManager.class); ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); listAppender.start(); notificationServiceLogger.addAppender(listAppender); String configFileOutput = CONFIGURATION_FILE_TEXT_BLANK_KEYSTORE_PASSWORD.replace("${test.server}", String.valueOf(mockWebServer.url("/"))); IOUtil.writeText(configFileOutput, new File(tempConfigFilePath)); NotificationServiceManager notificationServiceManager = new NotificationServiceManager(); notificationServiceManager.setMaxNotificationAttempts(1); notificationServiceManager.loadNotificationServices(new File(tempConfigFilePath)); List<ILoggingEvent> logsList = listAppender.list; boolean notificationServiceFailed = false; for (ILoggingEvent logMessage : logsList) { if (logMessage.getFormattedMessage().contains("'Keystore Password' validated against '' is invalid because Keystore Password cannot be empty")) { notificationServiceFailed = true; } } assertTrue(notificationServiceFailed); }
Example 5
Source File: TestHttpNotificationServiceSSL.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testStartNotificationFailsCorrectKeystorePasswdBlankKeypasswd() throws ParserConfigurationException, SAXException, IOException { Logger notificationServiceLogger = (Logger) LoggerFactory.getLogger(NotificationServiceManager.class); ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); listAppender.start(); notificationServiceLogger.addAppender(listAppender); String configFileOutput = CONFIGURATION_FILE_TEXT_BLANK_KEY_PASSWORD.replace("${test.server}", String.valueOf(mockWebServer.url("/"))); IOUtil.writeText(configFileOutput, new File(tempConfigFilePath)); NotificationServiceManager notificationServiceManager = new NotificationServiceManager(); notificationServiceManager.setMaxNotificationAttempts(1); notificationServiceManager.loadNotificationServices(new File(tempConfigFilePath)); List<ILoggingEvent> logsList = listAppender.list; boolean notificationServiceFailed = false; for (ILoggingEvent logMessage : logsList) { if (logMessage.getFormattedMessage().contains("'Key Password' validated against '' is invalid because Key Password cannot be empty")) { notificationServiceFailed = true; } } assertTrue(notificationServiceFailed); }
Example 6
Source File: OfframpClientImplTest.java From data-highway with Apache License 2.0 | 5 votes |
@Test public void onNext_Error() throws Exception { Logger OfframpClientImplLogger = (Logger) LoggerFactory.getLogger(OfframpClientImpl.class); ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); listAppender.start(); OfframpClientImplLogger.addAppender(listAppender); Error error = new Error("That thing was wrong"); underTest.onNext(error); List<ILoggingEvent> logsList = listAppender.list; assertThat(logsList.get(0).getMessage(), is("That thing was wrong")); assertEquals(Level.ERROR, logsList.get(0).getLevel()); }
Example 7
Source File: TestFileSystemRepository.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testMinimalArchiveCleanupIntervalHonoredAndLogged() throws Exception { // We are going to construct our own repository using different properties, so // we need to shutdown the existing one. shutdown(); Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); ListAppender<ILoggingEvent> testAppender = new ListAppender<>(); testAppender.setName("Test"); testAppender.start(); root.addAppender(testAppender); final Map<String, String> addProps = new HashMap<>(); addProps.put(NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY, "1 millis"); final NiFiProperties localProps = NiFiProperties.createBasicNiFiProperties(null, addProps); repository = new FileSystemRepository(localProps); repository.initialize(new StandardResourceClaimManager()); repository.purge(); boolean messageFound = false; String message = "The value of nifi.content.repository.archive.cleanup.frequency property " + "is set to '1 millis' which is below the allowed minimum of 1 second (1000 milliseconds). " + "Minimum value of 1 sec will be used as scheduling interval for archive cleanup task."; for (ILoggingEvent event : testAppender.list) { String actualMessage = event.getFormattedMessage(); if (actualMessage.equals(message)) { assertEquals(event.getLevel(), Level.WARN); messageFound = true; break; } } assertTrue(messageFound); }
Example 8
Source File: LoggingTestSupport.java From styx with Apache License 2.0 | 5 votes |
private ListAppender<ILoggingEvent> addListAppender() { ListAppender<ILoggingEvent> appender = new ListAppender<>(); appender.setContext((Context) LoggerFactory.getILoggerFactory()); appender.start(); logger.addAppender(appender); return appender; }
Example 9
Source File: LoggerTestHelper.java From qpid-broker-j with Apache License 2.0 | 5 votes |
public static ListAppender createAndRegisterAppender(String appenderName) { ListAppender appender = new ListAppender(); appender.setName(appenderName); ROOT_LOGGER.addAppender(appender); appender.start(); return appender; }
Example 10
Source File: RequestContextExportingAppenderTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void testMutabilityAndImmutability() { final AttributeKey<Object> someAttr = AttributeKey.valueOf(RequestContextExportingAppenderTest.class, "SOME_ATTR"); final RequestContextExportingAppender a = new RequestContextExportingAppender(); // Ensure mutability before start. a.addBuiltIn(BuiltInProperty.ELAPSED_NANOS); a.addAttribute("some-attr", someAttr); a.addRequestHeader(HttpHeaderNames.USER_AGENT); a.addResponseHeader(HttpHeaderNames.SET_COOKIE); final ListAppender<ILoggingEvent> la = new ListAppender<>(); a.addAppender(la); a.start(); la.start(); // Ensure immutability after start. assertThatThrownBy(() -> a.addBuiltIn(BuiltInProperty.REQ_PATH)) .isExactlyInstanceOf(IllegalStateException.class); assertThatThrownBy(() -> a.addAttribute("my-attr", MY_ATTR)) .isExactlyInstanceOf(IllegalStateException.class); assertThatThrownBy(() -> a.addRequestHeader(HttpHeaderNames.ACCEPT)) .isExactlyInstanceOf(IllegalStateException.class); assertThatThrownBy(() -> a.addResponseHeader(HttpHeaderNames.DATE)) .isExactlyInstanceOf(IllegalStateException.class); }
Example 11
Source File: RequestContextExportingAppenderTest.java From armeria with Apache License 2.0 | 5 votes |
@SafeVarargs private final List<ILoggingEvent> prepare(Consumer<RequestContextExportingAppender>... configurators) { final RequestContextExportingAppender a = new RequestContextExportingAppender(); for (Consumer<RequestContextExportingAppender> c : configurators) { c.accept(a); } final ListAppender<ILoggingEvent> la = new ListAppender<>(); a.addAppender(la); a.start(); la.start(); testLogger.addAppender(a); return la.list; }
Example 12
Source File: ExchangeRateServiceTest.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
@BeforeAll static void setup() { // Get the logger object for logs in ExchangeRateService exchangeRateServiceLogger = (Logger) LoggerFactory.getLogger(ExchangeRateService.class); // Initiate and append a ListAppender, which allows us to programmatically inspect // log messages ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); listAppender.setName(LIST_APPENDER_NAME); listAppender.start(); exchangeRateServiceLogger.addAppender(listAppender); }
Example 13
Source File: QueueMessageHandlerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void getMappingForMethod_methodWithDeletionPolicyNeverWithoutParameterTypeAcknowledgment_warningMustBeLogged() throws Exception { // Arrange QueueMessageHandler queueMessageHandler = new QueueMessageHandler(); Method receiveMethod = SqsListenerDeletionPolicyNeverNoAcknowledgment.class .getMethod("receive", String.class); LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory(); ListAppender<ILoggingEvent> appender = new ListAppender<>(); appender.start(); Logger log = logContext.getLogger(QueueMessageHandler.class); log.setLevel(Level.WARN); log.addAppender(appender); appender.setContext(log.getLoggerContext()); // Act queueMessageHandler.getMappingForMethod(receiveMethod, null); // Assert ILoggingEvent loggingEvent = appender.list.get(0); assertThat(loggingEvent.getLevel()).isSameAs(Level.WARN); assertThat(loggingEvent.getMessage().contains("receive")).isTrue(); assertThat(loggingEvent.getMessage().contains( "org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest$SqsListener" + "DeletionPolicyNeverNoAcknowledgment")).isTrue(); }
Example 14
Source File: QueueMessageHandlerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void processHandlerMethodException_invocableHandlerMethodNotAvailable_errorMustBeLogged() { // Arrange StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("sqsListenerWithoutMessageExceptionHandler", SqsListenerWithoutMessageExceptionHandler.class); applicationContext.registerBeanDefinition("queueMessageHandler", getQueueMessageHandlerBeanDefinition()); applicationContext.refresh(); MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class); LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory(); ListAppender<ILoggingEvent> appender = new ListAppender<>(); appender.start(); Logger log = logContext.getLogger(QueueMessageHandler.class); log.setLevel(Level.ERROR); log.addAppender(appender); appender.setContext(log.getLoggerContext()); // Act assertThatThrownBy( () -> messageHandler .handleMessage(MessageBuilder.withPayload("testContent") .setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "receive") .build())).isInstanceOf(MessagingException.class); // Assert assertThat(appender.list).hasSize(1); }
Example 15
Source File: TestFileSystemRepository.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testMinimalArchiveCleanupIntervalHonoredAndLogged() throws Exception { // We are going to construct our own repository using different properties, so // we need to shutdown the existing one. shutdown(); Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); ListAppender<ILoggingEvent> testAppender = new ListAppender<>(); testAppender.setName("Test"); testAppender.start(); root.addAppender(testAppender); final Map<String, String> addProps = new HashMap<>(); addProps.put(NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY, "1 millis"); final NiFiProperties localProps = NiFiProperties.createBasicNiFiProperties(TestFileSystemRepository.class.getResource("/conf/nifi.properties").getFile(), addProps); repository = new FileSystemRepository(localProps); repository.initialize(new StandardResourceClaimManager()); repository.purge(); boolean messageFound = false; String message = "The value of nifi.content.repository.archive.cleanup.frequency property " + "is set to '1 millis' which is below the allowed minimum of 1 second (1000 milliseconds). " + "Minimum value of 1 sec will be used as scheduling interval for archive cleanup task."; // Must synchronize on testAppender, because the call to append() is synchronized and this synchronize // keyword guards testAppender.list. Since we are accessing testAppender.list, we must do so in a thread-safe manner. synchronized (testAppender) { for (ILoggingEvent event : testAppender.list) { String actualMessage = event.getFormattedMessage(); if (actualMessage.equals(message)) { assertEquals(event.getLevel(), Level.WARN); messageFound = true; break; } } } assertTrue(messageFound); }
Example 16
Source File: PeriodicalHealthChecksTest.java From james-project with Apache License 2.0 | 3 votes |
public static ListAppender<ILoggingEvent> getListAppenderForClass(Class clazz) { Logger logger = (Logger) LoggerFactory.getLogger(clazz); ListAppender<ILoggingEvent> loggingEventListAppender = new ListAppender<>(); loggingEventListAppender.start(); logger.addAppender(loggingEventListAppender); return loggingEventListAppender; }