Java Code Examples for ch.qos.logback.classic.Logger#info()
The following examples show how to use
ch.qos.logback.classic.Logger#info() .
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: LogbackTest.java From sofa-common-tools with Apache License 2.0 | 6 votes |
@Test public void testIndependentSpaceLogback() throws JoranException { URL url1 = LogbackTest.class.getResource("/com/alipay/sofa/rpc/log/logback/log-conf.xml"); LoggerContext loggerContext1 = new LoggerContext(); new ContextInitializer(loggerContext1).configureByResource(url1); ch.qos.logback.classic.Logger logger1 = loggerContext1.getLogger("com.foo.Bar"); logger1.info("log4j2 - 1"); Assert.assertNotNull(logger1); //logback logger 2 URL url2 = LogbackTest.class.getResource("/com/alipay/sofa/rpc/log/logback/logback_b.xml"); LoggerContext loggerContext2 = new LoggerContext(); new ContextInitializer(loggerContext2).configureByResource(url2); Logger logger2 = loggerContext2.getLogger("com.foo.Bar2"); logger2.info("log4j2 - 222"); Assert.assertNotNull(logger2); Assert.assertNotSame(logger1, logger2); }
Example 2
Source File: LogbackSmallTest.java From cloudwatchlogs-java-appender with Apache License 2.0 | 6 votes |
private void checkLog(String inMsg, Throwable inEx, String outMsg) throws Exception { PrintStream original = System.out; ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); Logger logger = (Logger) LoggerFactory.getLogger("logback_test"); logger.info(inMsg, inEx); Thread.sleep(1000); String stdOut = baos.toString("UTF-8"); assertThat(stdOut, containsString(outMsg)); assertThat(stdOut, containsString("my-custom-value")); assertThat(stdOut, not(containsString("my-invalid-value"))); System.setOut(original); }
Example 3
Source File: RedisBatchAppenderEmbeddedIT.java From logback-redis with Apache License 2.0 | 6 votes |
private void logMessages(long count, int statsInterval, String prefix) { Logger loggingTest = createRedisLogger(); for (int i = 0; i < count; i++) { MDC_UTILS.clear() .putIfPresent("seq", lastSequenceId.incrementAndGet()) .putIfPresent("someNumber", 1L) .putIfPresent("someString", "hello"); loggingTest.info(prefix + ":" + i); int messagesSent = i + 1; if (messagesSent % statsInterval == 0) { log().info("Messages sent so far: {}", messagesSent); } } log().info("Messages sent TOTAL: {}", count); }
Example 4
Source File: RunLogback.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Override public void runLatencyTest(final int samples, final Histogram histogram, final long nanoTimeCost, final int threadCount) { final Logger logger = LOGGER; for (int i = 0; i < samples; i++) { final long s1 = System.nanoTime(); logger.info(LATENCY_MSG); final long s2 = System.nanoTime(); final long value = s2 - s1 - nanoTimeCost; if (value > 0) { histogram.addObservation(value); } // wait 1 microsec final long PAUSE_NANOS = 10000 * threadCount; final long pauseStart = System.nanoTime(); while (PAUSE_NANOS > (System.nanoTime() - pauseStart)) { // busy spin } } }
Example 5
Source File: GenerateAuthnRequestResourceTest.java From verify-service-provider with MIT License | 5 votes |
@Test public void shouldLeaveMDCInPreviousStateAfterLogging() throws Exception { Logger logger = (Logger) LoggerFactory.getLogger(AuthnRequestAttributesHelper.class); Appender<ILoggingEvent> appender = mock(Appender.class); logger.addAppender(appender); // Log and then Check state of MDC before calling the resource MDC.put("testMDCKey", "testMDCValue"); logger.info("Do some logging to see what's on the MDC beforehand..."); ArgumentCaptor<ILoggingEvent> loggingEventArgumentCaptor = ArgumentCaptor.forClass(ILoggingEvent.class); verify(appender).doAppend(loggingEventArgumentCaptor.capture()); int mdcPropertyMapSizeBeforeCall = loggingEventArgumentCaptor.getValue().getMDCPropertyMap().size(); when(authnRequestFactory.build(any())).thenReturn(authnRequest); RequestGenerationBody requestGenerationBody = new RequestGenerationBody(LevelOfAssurance.LEVEL_2, null); Response response = resources.target(GENERATE_REQUEST_RESOURCE_PATH).request().post( Entity.entity(requestGenerationBody, MediaType.APPLICATION_JSON_TYPE) ); assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode()); verify(appender, Mockito.times(2)).doAppend(loggingEventArgumentCaptor.capture()); // Resource should have added 4 items and then removed them from the MDC, leaving anything that was there previously assertThat(loggingEventArgumentCaptor.getValue().getMDCPropertyMap().size()).isEqualTo(mdcPropertyMapSizeBeforeCall + 4); assertThat(MDC.get("testMDCKey")).isEqualTo("testMDCValue"); }
Example 6
Source File: SingularityExecutorLogging.java From Singularity with Apache License 2.0 | 5 votes |
public void stopTaskLogger(String taskId, Logger logger) { LOG.info("Stopping task logger for {}", taskId); try { logger.info("Task finished, stopping logger"); logger.detachAndStopAllAppenders(); logger.getLoggerContext().stop(); } catch (Throwable t) { LOG.error("While closing task logger for {}", taskId, t); } }
Example 7
Source File: LogbackIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void givenConfig_MessageFiltered() { Logger foobar = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.foobar"); Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback"); Logger testslogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback.tests"); foobar.debug("This is logged from foobar"); logger.debug("This is not logged from logger"); logger.info("This is logged from logger"); testslogger.info("This is not logged from tests"); testslogger.warn("This is logged from tests"); }
Example 8
Source File: RunLogback.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override public void runThroughputTest(final int lines, final Histogram histogram) { final long s1 = System.nanoTime(); final Logger logger = LOGGER; for (int j = 0; j < lines; j++) { logger.info(THROUGHPUT_MSG); } final long s2 = System.nanoTime(); final long opsPerSec = (1000L * 1000L * 1000L * lines) / (s2 - s1); histogram.addObservation(opsPerSec); }
Example 9
Source File: LogbackIntegrationTest.java From tutorials with MIT License | 4 votes |
@Test public void givenLogHierarchy_MessagesFiltered() { ch.qos.logback.classic.Logger parentLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback"); parentLogger.setLevel(Level.INFO); Logger childlogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger("com.baeldung.logback.tests"); parentLogger.warn("This message is logged because WARN > INFO."); // This request is disabled, because DEBUG < INFO. parentLogger.debug("This message is not logged because DEBUG < INFO."); childlogger.info("INFO == INFO"); childlogger.debug("DEBUG < INFO"); }
Example 10
Source File: LoggingBootstrapTest.java From hivemq-community-edition with Apache License 2.0 | 3 votes |
@Test public void test_logger_prepare_holds_back_logger_until_init_logging() throws Exception { try { final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); final LogbackCapturingAppender testAppender = LogbackCapturingAppender.Factory.weaveInto(logger); LoggingBootstrap.prepareLogging(); logger.info("testlog"); //The logging statement is cached and is not available yet assertFalse(testAppender.isLogCaptured()); //This "resets" to the original logger LoggingBootstrap.initLogging(temporaryFolder.newFolder()); assertTrue(testAppender.isLogCaptured()); final ImmutableList<Appender<ILoggingEvent>> appenders = ImmutableList.copyOf(logger.iteratorForAppenders()); for (final Appender<ILoggingEvent> appender : appenders) { if (appender instanceof ListAppender) { fail(); } } LogbackCapturingAppender.Factory.cleanUp(); } finally { resetLogToOriginal(); } }