From f5c553d9de82fc3a9d29dc4c6ef4c9ac090c773c Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 24 Jun 2009 23:58:58 +0000 Subject: [PATCH] INT-685 --- .../xml/LoggingChannelAdapterParser.java | 7 ++++++- .../config/xml/spring-integration-1.0.xsd | 13 ++++++++++++ .../integration/handler/LoggingHandler.java | 20 +++++++++++++++---- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/LoggingChannelAdapterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/LoggingChannelAdapterParser.java index a4188f896a..9113abce09 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/LoggingChannelAdapterParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/LoggingChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.StringUtils; /** * Parser for the 'logging-channel-adapter' element. @@ -35,6 +36,10 @@ public class LoggingChannelAdapterParser extends AbstractOutboundChannelAdapterP BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( IntegrationNamespaceUtils.BASE_PACKAGE + ".handler.LoggingHandler"); builder.addConstructorArgValue(element.getAttribute("level")); + String logFullMessage = element.getAttribute("log-full-message"); + if (StringUtils.hasText(logFullMessage)) { + builder.addPropertyValue("shouldLogFullMessage", logFullMessage); + } return builder.getBeanDefinition(); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/spring-integration-1.0.xsd b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/spring-integration-1.0.xsd index a7367127fa..63746bcdb2 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/spring-integration-1.0.xsd +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/spring-integration-1.0.xsd @@ -288,6 +288,11 @@ + + + @@ -299,6 +304,14 @@ + + + + + diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/handler/LoggingHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/handler/LoggingHandler.java index bccdae4add..19c17dc7fa 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/handler/LoggingHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/handler/LoggingHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,10 @@ import org.springframework.integration.core.Message; import org.springframework.util.StringUtils; /** - * MessageHandler implementation that logs the Message payload. If the payload - * is assignable to Throwable, it will log the stack trace. + * MessageHandler implementation that simply logs the Message or its payload + * depending on the value of the 'shouldLogFullMessage' property. If logging + * the payload, and it is assignable to Throwable, it will log the stack trace. + * By default, it will log the payload only. * * @author Mark Fisher * @since 1.0.1 @@ -34,6 +36,8 @@ public class LoggingHandler extends AbstractMessageHandler { private static enum Level { FATAL, ERROR, WARN, INFO, DEBUG, TRACE }; + private boolean shouldLogFullMessage; + private final Level level; @@ -52,9 +56,17 @@ public class LoggingHandler extends AbstractMessageHandler { } + /** + * Specify whether to log the full Message. Otherwise, only the payload + * will be logged. This value is false by default. + */ + public void setShouldLogFullMessage(boolean shouldLogFullMessage) { + this.shouldLogFullMessage = shouldLogFullMessage; + } + @Override protected void handleMessageInternal(Message message) throws Exception { - Object logMessage = message.getPayload(); + Object logMessage = (this.shouldLogFullMessage) ? message : message.getPayload(); if (logMessage instanceof Throwable) { StringWriter stringWriter = new StringWriter(); ((Throwable) logMessage).printStackTrace(new PrintWriter(stringWriter, true));