List of usage examples for org.apache.commons.logging Log isInfoEnabled
boolean isInfoEnabled();
From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java
@Test public void testExpression() throws Exception { TestXMPPConnection testXMPPConnection = new TestXMPPConnection(); QueueChannel inputChannel = new QueueChannel(); ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(testXMPPConnection); SpelExpressionParser parser = new SpelExpressionParser(); endpoint.setPayloadExpression(parser.parseExpression("#root")); endpoint.setOutputChannel(inputChannel); endpoint.setBeanFactory(mock(BeanFactory.class)); endpoint.afterPropertiesSet();// ww w . j av a2 s . co m endpoint.start(); Message smackMessage = new Message(); smackMessage.setBody("foo"); XmlPullParser xmlPullParser = PacketParserUtils.newXmppParser(new StringReader(smackMessage.toString())); xmlPullParser.next(); testXMPPConnection.parseAndProcessStanza(xmlPullParser); org.springframework.messaging.Message<?> receive = inputChannel.receive(10000); assertNotNull(receive); Object payload = receive.getPayload(); assertThat(payload, instanceOf(Message.class)); assertEquals(smackMessage.getStanzaId(), ((Message) payload).getStanzaId()); assertEquals(smackMessage.getBody(), ((Message) payload).getBody()); Log logger = Mockito.spy(TestUtils.getPropertyValue(endpoint, "logger", Log.class)); given(logger.isInfoEnabled()).willReturn(true); final CountDownLatch logLatch = new CountDownLatch(1); willAnswer(invocation -> { Object result = invocation.callRealMethod(); logLatch.countDown(); return result; }).given(logger).info(anyString()); new DirectFieldAccessor(endpoint).setPropertyValue("logger", logger); endpoint.setPayloadExpression(null); smackMessage = new Message(); xmlPullParser = PacketParserUtils.newXmppParser(new StringReader(smackMessage.toString())); xmlPullParser.next(); testXMPPConnection.parseAndProcessStanza(xmlPullParser); ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class); assertTrue(logLatch.await(10, TimeUnit.SECONDS)); verify(logger).info(argumentCaptor.capture()); assertEquals("The XMPP Message [" + smackMessage + "] with empty body is ignored.", argumentCaptor.getValue()); endpoint.stop(); }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testInfoNoEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.INFO); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); logger.log(() -> "foo"); verify(theLogger).isInfoEnabled();/*from w w w .j ava 2s . c o m*/ verify(theLogger).info(any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testDebugNoEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.DEBUG); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); given(theLogger.isDebugEnabled()).willReturn(true); logger.log(() -> "foo"); verify(theLogger).isDebugEnabled();/* w w w . jav a 2 s . c o m*/ verify(theLogger).debug(any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testTraceNoEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.TRACE); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); given(theLogger.isDebugEnabled()).willReturn(true); given(theLogger.isTraceEnabled()).willReturn(true); logger.log(() -> "foo"); verify(theLogger).isTraceEnabled();/*from ww w .j av a 2s. co m*/ verify(theLogger).trace(any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testInfoWithEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.INFO); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); logger.log(() -> "foo", rte); verify(theLogger).isInfoEnabled();//from ww w . jav a 2 s . com verify(theLogger).info(any(), any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testDebugWithEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.DEBUG); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); given(theLogger.isDebugEnabled()).willReturn(true); logger.log(() -> "foo", rte); verify(theLogger).isDebugEnabled();/*w ww . j a va2s . co m*/ verify(theLogger).debug(any(), any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.kafka.support.LogIfLevelEnabledTests.java
@Test public void testTraceWithEx() { Log theLogger = mock(Log.class); LogIfLevelEnabled logger = new LogIfLevelEnabled(theLogger, LogIfLevelEnabled.Level.TRACE); given(theLogger.isFatalEnabled()).willReturn(true); given(theLogger.isErrorEnabled()).willReturn(true); given(theLogger.isWarnEnabled()).willReturn(true); given(theLogger.isInfoEnabled()).willReturn(true); given(theLogger.isDebugEnabled()).willReturn(true); given(theLogger.isTraceEnabled()).willReturn(true); logger.log(() -> "foo", rte); verify(theLogger).isTraceEnabled();/* w w w .j a v a2 s.com*/ verify(theLogger).trace(any(), any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.orm.toplink.support.CommonsLoggingSessionLog.java
public void log(SessionLogEntry entry) { Log logger = LogFactory.getLog(getCategory(entry)); switch (entry.getLevel()) { case SEVERE:// w w w. ja va2s . c o m if (logger.isErrorEnabled()) { if (entry.hasException()) { logger.error(getMessageString(entry), getException(entry)); } else { logger.error(getMessageString(entry)); } } break; case WARNING: if (logger.isWarnEnabled()) { if (entry.hasException()) { logger.warn(getMessageString(entry), getException(entry)); } else { logger.warn(getMessageString(entry)); } } break; case INFO: if (logger.isInfoEnabled()) { if (entry.hasException()) { logger.info(getMessageString(entry), getException(entry)); } else { logger.info(getMessageString(entry)); } } break; case CONFIG: case FINE: case FINER: if (logger.isDebugEnabled()) { if (entry.hasException()) { logger.debug(getMessageString(entry), getException(entry)); } else { logger.debug(getMessageString(entry)); } } break; case FINEST: if (logger.isTraceEnabled()) { if (entry.hasException()) { logger.trace(getMessageString(entry), getException(entry)); } else { logger.trace(getMessageString(entry)); } } break; } }
From source file:org.springframework.web.context.ContextLoader.java
/** * Initialize Spring's web application context for the given servlet context, * using the application context provided at construction time, or creating a new one * according to the "{@link #CONTEXT_CLASS_PARAM contextClass}" and * "{@link #CONFIG_LOCATION_PARAM contextConfigLocation}" context-params. * @param servletContext current servlet context * @return the new WebApplicationContext * @see #ContextLoader(WebApplicationContext) * @see #CONTEXT_CLASS_PARAM//w ww . j a va 2 s . co m * @see #CONFIG_LOCATION_PARAM */ public WebApplicationContext initWebApplicationContext(ServletContext servletContext) { if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) { throw new IllegalStateException( "Cannot initialize context because there is already a root application context present - " + "check whether you have multiple ContextLoader* definitions in your web.xml!"); } Log logger = LogFactory.getLog(ContextLoader.class); servletContext.log("Initializing Spring root WebApplicationContext"); if (logger.isInfoEnabled()) { logger.info("Root WebApplicationContext: initialization started"); } long startTime = System.currentTimeMillis(); try { // Store context in local instance variable, to guarantee that // it is available on ServletContext shutdown. if (this.context == null) { this.context = createWebApplicationContext(servletContext); } if (this.context instanceof ConfigurableWebApplicationContext) { ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) this.context; if (!cwac.isActive()) { // The context has not yet been refreshed -> provide services such as // setting the parent context, setting the application context id, etc if (cwac.getParent() == null) { // The context instance was injected without an explicit parent -> // determine parent for root web application context, if any. ApplicationContext parent = loadParentContext(servletContext); cwac.setParent(parent); } configureAndRefreshWebApplicationContext(cwac, servletContext); } } servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context); ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl == ContextLoader.class.getClassLoader()) { currentContext = this.context; } else if (ccl != null) { currentContextPerThread.put(ccl, this.context); } if (logger.isDebugEnabled()) { logger.debug("Published root WebApplicationContext as ServletContext attribute with name [" + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]"); } if (logger.isInfoEnabled()) { long elapsedTime = System.currentTimeMillis() - startTime; logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms"); } return this.context; } catch (RuntimeException ex) { logger.error("Context initialization failed", ex); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex); throw ex; } catch (Error err) { logger.error("Context initialization failed", err); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err); throw err; } }
From source file:org.springframework.xd.dirt.launcher.AbstractContainerLauncher.java
protected void logContainerInfo(Log logger, XDContainer container) { if (logger.isInfoEnabled()) { StringBuilder runtimeInfo = new StringBuilder(); runtimeInfo.append(this.getRuntimeInfo(container)); if (container.isJmxEnabled()) { runtimeInfo.append(//from w ww . jav a2 s .co m String.format("\nMBean Server: http://localhost:%d/jolokia/", container.getJmxPort())); } else { runtimeInfo.append(" JMX is disabled for XD components"); } runtimeInfo.append(logXDEnvironment(container)); logger.info(BannerUtils.displayBanner(container.getJvmName(), runtimeInfo.toString())); } }