Example usage for org.apache.commons.logging Log isWarnEnabled

List of usage examples for org.apache.commons.logging Log isWarnEnabled

Introduction

In this page you can find the example usage for org.apache.commons.logging Log isWarnEnabled.

Prototype

boolean isWarnEnabled();

Source Link

Document

Is warn logging currently enabled?

Usage

From source file:org.picocontainer.gems.monitors.CommonsLoggingComponentMonitor.java

/** {@inheritDoc} **/
public void lifecycleInvocationFailed(final MutablePicoContainer container,
        final ComponentAdapter<?> componentAdapter, final Method method, final Object instance,
        final RuntimeException cause) {
    Log log = getLog(method);
    if (log.isWarnEnabled()) {
        log.warn(ComponentMonitorHelper.format(ComponentMonitorHelper.LIFECYCLE_INVOCATION_FAILED,
                methodToString(method), instance, cause.getMessage()), cause);
    }//from   w w w.  ja  va  2 s  . c  om
    delegate.lifecycleInvocationFailed(container, componentAdapter, method, instance, cause);
}

From source file:org.picocontainer.gems.monitors.CommonsLoggingComponentMonitor.java

/** {@inheritDoc} **/
public Object noComponentFound(final MutablePicoContainer container, final Object componentKey) {
    Log log = this.log != null ? this.log : LogFactory.getLog(ComponentMonitor.class);
    if (log.isWarnEnabled()) {
        log.warn(ComponentMonitorHelper.format(ComponentMonitorHelper.NO_COMPONENT, componentKey));
    }/*from  w  w w  .j  a v  a 2s .  com*/
    return delegate.noComponentFound(container, componentKey);
}

From source file:org.saiku.reporting.backend.component.ReportContentUtil.java

/**
 * Apply inputs (if any) to corresponding report parameters, care is taken when
 * checking parameter types to perform any necessary casting and conversion.
 *
 * @param report The report to retrieve parameter definitions and values from.         
 * @param context a ParameterContext for which the parameters will be under
 * @param validationResult the validation result that will hold the warnings. If null, a new one will be created.
 * @return the validation result containing any parameter validation errors.
 * @throws java.io.IOException if the report of this component could not be parsed.
 * @throws ResourceException   if the report of this component could not be parsed.
 *///from   w ww .  j a v  a 2s .  c o  m
public static ValidationResult applyInputsToReportParameters(final MasterReport report,
        final ParameterContext context, final Map<String, Object> inputs, ValidationResult validationResult)
        throws IOException, ResourceException {
    if (validationResult == null) {
        validationResult = new ValidationResult();
    }
    // apply inputs to report
    if (inputs != null) {
        final Log log = LogFactory.getLog(ReportContentUtil.class);
        final ParameterDefinitionEntry[] params = report.getParameterDefinition().getParameterDefinitions();
        final ReportParameterValues parameterValues = report.getParameterValues();
        for (final ParameterDefinitionEntry param : params) {
            final String paramName = param.getName();
            try {
                final Object computedParameter = ReportContentUtil.computeParameterValue(context, param,
                        inputs.get(paramName));
                parameterValues.put(param.getName(), computedParameter);
                if (log.isInfoEnabled()) {
                    log.info("ReportPlugin.infoParameterValues" + paramName + " "
                            + String.valueOf(inputs.get(paramName)) + " " + String.valueOf(computedParameter));
                }
            } catch (Exception e) {
                if (log.isWarnEnabled()) {
                    log.warn("ReportPlugin.logErrorParametrization" + e.getMessage()); //$NON-NLS-1$
                }
                validationResult.addError(paramName, new ValidationMessage(e.getMessage()));
            }
        }
    }
    return validationResult;
}

From source file:org.seasar.mayaa.impl.util.xml.XMLHandler.java

public InputSource resolveEntity(String publicId, String systemId) {
    String path = systemId;/*from   w  w w.ja va2  s .  c  o m*/
    Map entities = getEntityMap();
    if (entities != null && entities.containsKey(publicId)) {
        path = (String) entities.get(publicId);
    } else if (entities != null && entities.containsKey(systemId)) {
        path = (String) entities.get(systemId);
    } else {
        int pos = systemId.lastIndexOf('/');
        if (pos != -1) {
            path = systemId.substring(pos);
        }
    }
    Class neighborClass = getNeighborClass();
    if (neighborClass == null) {
        neighborClass = getClass();
    }
    ClassLoaderSourceDescriptor source = new ClassLoaderSourceDescriptor();
    source.setSystemID(path);
    source.setNeighborClass(neighborClass);
    if (source.exists()) {
        InputSource ret = new InputSource(source.getInputStream());
        ret.setPublicId(publicId);
        ret.setSystemId(path);
        return ret;
    }
    Log log = getLog();
    if (log != null && log.isWarnEnabled()) {
        String message = StringUtil.getMessage(XMLHandler.class, 0, publicId, systemId);
        log.warn(message);
    }
    return null;
}

From source file:org.seasar.mayaa.impl.util.xml.XMLHandler.java

public void warning(SAXParseException e) {
    Log log = getLog();
    if (log != null && log.isWarnEnabled()) {
        log.warn(e.getMessage(), e);//from  www . j  av  a  2s . c  o m
    }
}

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;
    }/*  w w  w.j  av a  2 s  .c om*/
    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.amqp.channel.DispatcherHasNoSubscribersTests.java

private List<String> insertMockLoggerInListener(PublishSubscribeAmqpChannel channel) {
    SimpleMessageListenerContainer container = TestUtils.getPropertyValue(channel, "container",
            SimpleMessageListenerContainer.class);
    Log logger = mock(Log.class);
    final ArrayList<String> logList = new ArrayList<String>();
    doAnswer(new Answer<Object>() {
        public Object answer(InvocationOnMock invocation) throws Throwable {
            String message = (String) invocation.getArguments()[0];
            if (message.startsWith("Dispatcher has no subscribers")) {
                logList.add(message);//from ww  w  .j  a  v a 2 s.  c  o  m
            }
            return null;
        }
    }).when(logger).warn(anyString(), any(Exception.class));
    when(logger.isWarnEnabled()).thenReturn(true);
    Object listener = container.getMessageListener();
    DirectFieldAccessor dfa = new DirectFieldAccessor(listener);
    dfa.setPropertyValue("logger", logger);
    return logList;
}

From source file:org.springframework.integration.config.annotation.CustomMessagingAnnotationTests.java

@Test
public void testLogAnnotation() {
    assertNotNull(this.loggingHandler);

    Log log = spy(TestUtils.getPropertyValue(this.loggingHandler, "messageLogger", Log.class));

    given(log.isWarnEnabled()).willReturn(true);

    new DirectFieldAccessor(this.loggingHandler).setPropertyValue("messageLogger", log);

    this.loggingChannel.send(MessageBuilder.withPayload("foo").setHeader("bar", "baz").build());

    ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);

    verify(log).warn(argumentCaptor.capture());

    assertEquals("foo for baz", argumentCaptor.getValue());
}

From source file:org.springframework.integration.config.ChainParserTests.java

@Test //INT-2275, INT-2958
public void chainWithLoggingChannelAdapter() {
    Log logger = mock(Log.class);
    final AtomicReference<String> log = new AtomicReference<String>();
    when(logger.isWarnEnabled()).thenReturn(true);
    doAnswer(new Answer<Object>() {
        public Object answer(InvocationOnMock invocation) throws Throwable {
            log.set((String) invocation.getArguments()[0]);
            return null;
        }//from  ww  w .  j  a  v a2 s. co m
    }).when(logger).warn(any());

    @SuppressWarnings("unchecked")
    List<MessageHandler> handlers = TestUtils.getPropertyValue(this.logChain, "handlers", List.class);
    MessageHandler handler = handlers.get(2);
    assertTrue(handler instanceof LoggingHandler);
    DirectFieldAccessor dfa = new DirectFieldAccessor(handler);
    dfa.setPropertyValue("messageLogger", logger);

    this.loggingChannelAdapterChannel
            .send(MessageBuilder.withPayload(new byte[] { 116, 101, 115, 116 }).build());
    assertNotNull(log.get());
    assertEquals("TEST", log.get());
}

From source file:org.springframework.integration.handler.advice.AdvisedMessageHandlerTests.java

@Test
public void testInappropriateAdvice() throws Exception {
    final AtomicBoolean called = new AtomicBoolean(false);
    Advice advice = new AbstractRequestHandlerAdvice() {
        @Override/* www  .jav  a  2  s. c  om*/
        protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message)
                throws Exception {
            called.set(true);
            return callback.execute();
        }
    };
    PollableChannel inputChannel = new QueueChannel();
    PollingConsumer consumer = new PollingConsumer(inputChannel, new MessageHandler() {
        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
        }
    });
    consumer.setAdviceChain(Collections.singletonList(advice));
    consumer.setTaskExecutor(
            new ErrorHandlingTaskExecutor(Executors.newSingleThreadExecutor(), new ErrorHandler() {
                @Override
                public void handleError(Throwable t) {
                }
            }));
    consumer.afterPropertiesSet();

    Callable<?> pollingTask = TestUtils.getPropertyValue(consumer, "poller.pollingTask", Callable.class);
    assertTrue(AopUtils.isAopProxy(pollingTask));
    Log logger = TestUtils.getPropertyValue(advice, "logger", Log.class);
    logger = spy(logger);
    when(logger.isWarnEnabled()).thenReturn(Boolean.TRUE);
    final AtomicReference<String> logMessage = new AtomicReference<String>();
    doAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            logMessage.set((String) invocation.getArguments()[0]);
            return null;
        }
    }).when(logger).warn(Mockito.anyString());
    DirectFieldAccessor accessor = new DirectFieldAccessor(advice);
    accessor.setPropertyValue("logger", logger);

    pollingTask.call();
    assertFalse(called.get());
    assertNotNull(logMessage.get());
    assertTrue(logMessage.get()
            .endsWith("can only be used for MessageHandlers; " + "an attempt to advise method 'call' in "
                    + "'org.springframework.integration.endpoint.AbstractPollingEndpoint$1' is ignored"));
}