INT-685
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -288,6 +288,11 @@
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="channelAdapterType">
|
||||
<xsd:attribute name="level" default="INFO">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specify the log level.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="FATAL" />
|
||||
@@ -299,6 +304,14 @@
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="log-full-message">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specify whether to log the full message. If false, only the payload will be logged.
|
||||
This value will be false by default.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
@@ -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 <code>false</code> 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));
|
||||
|
||||
Reference in New Issue
Block a user