List of usage examples for org.apache.commons.logging Log isTraceEnabled
boolean isTraceEnabled();
From source file:org.springframework.flex.core.CommonsLoggingTarget.java
public void logEvent(LogEvent logevent) { String category = logevent.logger.getCategory(); if (this.categoryPrefix != null) { category = this.categoryPrefix + "." + category; }/*from ww w.ja v a2 s. co m*/ Log log = LogFactory.getLog(category); switch (logevent.level) { case LogEvent.FATAL: if (log.isFatalEnabled()) { log.fatal(logevent.message, logevent.throwable); } break; case LogEvent.ERROR: if (log.isErrorEnabled()) { log.error(logevent.message, logevent.throwable); } break; case LogEvent.WARN: if (log.isWarnEnabled()) { log.warn(logevent.message, logevent.throwable); } break; case LogEvent.INFO: if (log.isInfoEnabled()) { log.info(logevent.message, logevent.throwable); } break; case LogEvent.DEBUG: if (log.isDebugEnabled()) { log.debug(logevent.message, logevent.throwable); } break; case LogEvent.ALL: if (log.isTraceEnabled()) { log.trace(logevent.message, logevent.throwable); } break; default: break; } }
From source file:org.springframework.integration.channel.QueueChannelTests.java
@Test public void testSimpleSendAndReceive() throws Exception { final AtomicBoolean messageReceived = new AtomicBoolean(false); final CountDownLatch latch = new CountDownLatch(1); final QueueChannel channel = new QueueChannel(); Log logger = spy(TestUtils.getPropertyValue(channel, "logger", Log.class)); when(logger.isDebugEnabled()).thenReturn(true); when(logger.isTraceEnabled()).thenReturn(true); new DirectFieldAccessor(channel).setPropertyValue("logger", logger); new Thread(new Runnable() { @Override/*w w w .j a v a 2 s . co m*/ public void run() { Message<?> message = channel.receive(); if (message != null) { messageReceived.set(true); latch.countDown(); } } }).start(); assertFalse(messageReceived.get()); channel.send(new GenericMessage<String>("testing")); latch.await(1000, TimeUnit.MILLISECONDS); assertTrue(messageReceived.get()); ArgumentCaptor<String> preCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> postCaptor = ArgumentCaptor.forClass(String.class); verify(logger).trace(preCaptor.capture()); verify(logger, times(3)).debug(postCaptor.capture()); assertThat(preCaptor.getValue(), startsWith("preReceive")); assertThat(postCaptor.getValue(), startsWith("postReceive")); }
From source file:org.springframework.integration.smb.session.SmbSession.java
/** * Static configuration of the JCIFS library. * The log level of this class is mapped to a suitable <code>jcifs.util.loglevel</code> *///from w w w. j av a 2 s . c om static void configureJcifs() { // TODO jcifs.Config.setProperty("jcifs.smb.client.useExtendedSecurity", "false"); // TODO jcifs.Config.setProperty("jcifs.smb.client.disablePlainTextPasswords", "false"); // set JCIFS SMB client library' log level unless already configured by system property final String sysPropLogLevel = "jcifs.util.loglevel"; if (jcifs.Config.getProperty(sysPropLogLevel) == null) { // set log level according to this class' logger's log level. Log log = LogFactory.getLog(SmbSession.class); if (log.isTraceEnabled()) { jcifs.Config.setProperty(sysPropLogLevel, "N"); } else if (log.isDebugEnabled()) { jcifs.Config.setProperty(sysPropLogLevel, "3"); } else { jcifs.Config.setProperty(sysPropLogLevel, "1"); } } }
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();/* w ww. ja v a 2 s.co m*/ verify(theLogger).trace(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. jav a 2s.c om verify(theLogger).trace(any(), any()); verifyNoMoreInteractions(theLogger); }
From source file:org.springframework.kafka.support.SeekUtils.java
/** * Seek records to earliest position, optionally skipping the first. * @param records the records.//from www . j a v a 2 s. c o m * @param consumer the consumer. * @param exception the exception * @param recoverable true if skipping the first record is allowed. * @param skipper function to determine whether or not to skip seeking the first. * @param logger a {@link Log} for seek errors. * @return true if the failed record was skipped. */ public static boolean doSeeks(List<ConsumerRecord<?, ?>> records, Consumer<?, ?> consumer, Exception exception, boolean recoverable, BiPredicate<ConsumerRecord<?, ?>, Exception> skipper, Log logger) { Map<TopicPartition, Long> partitions = new LinkedHashMap<>(); AtomicBoolean first = new AtomicBoolean(true); AtomicBoolean skipped = new AtomicBoolean(); records.forEach(record -> { if (recoverable && first.get()) { skipped.set(skipper.test(record, exception)); if (skipped.get() && logger.isDebugEnabled()) { logger.debug("Skipping seek of: " + record); } } if (!recoverable || !first.get() || !skipped.get()) { partitions.computeIfAbsent(new TopicPartition(record.topic(), record.partition()), offset -> record.offset()); } first.set(false); }); boolean tracing = logger.isTraceEnabled(); partitions.forEach((topicPartition, offset) -> { try { if (tracing) { logger.trace("Seeking: " + topicPartition + " to: " + offset); } consumer.seek(topicPartition, offset); } catch (Exception e) { logger.error("Failed to seek " + topicPartition + " to " + offset, e); } }); return skipped.get(); }
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 ww . j a v a2 s . c om*/ 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.xd.dirt.integration.bus.rabbit.RabbitMessageBusTests.java
@SuppressWarnings("unchecked") @Test/*from ww w. j a va2 s .c o m*/ public void testBatchingAndCompression() throws Exception { RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource()); MessageBus bus = getMessageBus(); Properties properties = new Properties(); properties.put("deliveryMode", "NON_PERSISTENT"); properties.put("batchingEnabled", "true"); properties.put("batchSize", "2"); properties.put("batchBufferLimit", "100000"); properties.put("batchTimeout", "30000"); properties.put("compress", "true"); DirectChannel output = new DirectChannel(); output.setBeanName("batchingProducer"); bus.bindProducer("batching.0", output, properties); while (template.receive("xdbus.batching.0") != null) { } Log logger = spy(TestUtils.getPropertyValue(bus, "messageBus.compressingPostProcessor.logger", Log.class)); new DirectFieldAccessor(TestUtils.getPropertyValue(bus, "messageBus.compressingPostProcessor")) .setPropertyValue("logger", logger); when(logger.isTraceEnabled()).thenReturn(true); assertEquals(Deflater.BEST_SPEED, TestUtils.getPropertyValue(bus, "messageBus.compressingPostProcessor.level")); output.send(new GenericMessage<>("foo".getBytes())); output.send(new GenericMessage<>("bar".getBytes())); Object out = spyOn("batching.0").receive(false); assertThat(out, instanceOf(byte[].class)); assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String((byte[]) out)); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); verify(logger).trace(captor.capture()); assertThat(captor.getValue().toString(), containsString("Compressed 14 to ")); QueueChannel input = new QueueChannel(); input.setBeanName("batchingConsumer"); bus.bindConsumer("batching.0", input, null); output.send(new GenericMessage<>("foo".getBytes())); output.send(new GenericMessage<>("bar".getBytes())); Message<byte[]> in = (Message<byte[]>) input.receive(10000); assertNotNull(in); assertEquals("foo", new String(in.getPayload())); in = (Message<byte[]>) input.receive(10000); assertNotNull(in); assertEquals("bar", new String(in.getPayload())); assertNull(in.getHeaders().get(AmqpHeaders.DELIVERY_MODE)); bus.unbindProducers("batching.0"); bus.unbindConsumers("batching.0"); }
From source file:org.talframework.tal.aspects.loggers.http.DefaultRequestLogger.java
/** * Logs out the request parameters and optionally the * request attributes for the first {@link HttpServletRequest} * argument to method./*ww w . j a va 2 s . co m*/ */ public void traceBefore(JoinPoint jp) { if (!logger.isDebugEnabled()) return; Log logger = LoggerHelper.getLogger(jp.getStaticPart().getSignature().getDeclaringType()); if (logger.isDebugEnabled()) { HttpServletRequest req = findRequest(jp); if (req == null) return; if (logger.isDebugEnabled()) logRequestParameters(req, logger); if (logger.isTraceEnabled()) logRequestAttributes(req, logger); } }
From source file:org.talframework.tal.aspects.loggers.http.DefaultRequestLogger.java
/** * Optionally logs out the ending request attributes and * session for the first {@link HttpServletRequest} argument * to the method. /*from w w w . j a va 2s . co m*/ */ public void traceAfter(JoinPoint jp, Object retVal) { if (!logger.isDebugEnabled()) return; Log logger = LoggerHelper.getLogger(jp.getStaticPart().getSignature().getDeclaringType()); if (logger.isDebugEnabled()) { HttpServletRequest req = findRequest(jp); if (req == null) return; if (logger.isTraceEnabled()) logRequestAttributes(req, logger); if (logger.isDebugEnabled()) logSessionAttributes(req, logger); } }