Backported INT-1947 and INT-1512 for core schema

LoggingHandler now has a loggerName property
  The <logging-channel-adapter> now has a 'logger-name' attribute
  changed xsd:ID types to xsd:string in spring-integration.xsd
This commit is contained in:
Mark Fisher
2011-08-13 14:05:54 -04:00
parent 6582f30e60
commit 7beaa19ea5
6 changed files with 109 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -46,6 +46,7 @@ public class LoggingChannelAdapterParser extends AbstractOutboundChannelAdapterP
}
builder.addPropertyValue("shouldLogFullMessage", logFullMessage);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "logger-name");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "expression");
return builder.getBeanDefinition();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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. You may obtain a copy of the License at
@@ -17,6 +17,9 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.expression.MapAccessor;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
@@ -24,6 +27,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.integration.Message;
import org.springframework.integration.dispatcher.AggregateMessageDeliveryException;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@@ -42,12 +46,16 @@ public class LoggingHandler extends AbstractMessageHandler {
private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
private volatile Expression expression;
private final Level level;
private final EvaluationContext evaluationContext;
private volatile Log messageLogger = this.logger;
/**
* Create a LoggingHandler with the given log level (case-insensitive).
* <p>
@@ -56,7 +64,8 @@ public class LoggingHandler extends AbstractMessageHandler {
public LoggingHandler(String level) {
try {
this.level = Level.valueOf(level.toUpperCase());
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid log level '" + level
+ "'. The (case-insensitive) supported values are: "
+ StringUtils.arrayToCommaDelimitedString(Level.values()));
@@ -66,11 +75,17 @@ public class LoggingHandler extends AbstractMessageHandler {
this.evaluationContext = evaluationContext;
this.expression = EXPRESSION_PARSER.parseExpression("payload");
}
public void setExpression(String expressionString) {
this.expression = EXPRESSION_PARSER.parseExpression(expressionString);
}
public void setLoggerName(String loggerName) {
Assert.hasText(loggerName, "loggerName must not be empty");
this.messageLogger = LogFactory.getLog(loggerName);
}
/**
* Specify whether to log the full Message. Otherwise, only the payload will be logged. This value is
* <code>false</code> by default.
@@ -102,33 +117,33 @@ public class LoggingHandler extends AbstractMessageHandler {
}
switch (this.level) {
case FATAL:
if (logger.isFatalEnabled()) {
logger.fatal(logMessage);
if (messageLogger.isFatalEnabled()) {
messageLogger.fatal(logMessage);
}
break;
case ERROR:
if (logger.isErrorEnabled()) {
logger.error(logMessage);
if (messageLogger.isErrorEnabled()) {
messageLogger.error(logMessage);
}
break;
case WARN:
if (logger.isWarnEnabled()) {
logger.warn(logMessage);
if (messageLogger.isWarnEnabled()) {
messageLogger.warn(logMessage);
}
break;
case INFO:
if (logger.isInfoEnabled()) {
logger.info(logMessage);
if (messageLogger.isInfoEnabled()) {
messageLogger.info(logMessage);
}
break;
case DEBUG:
if (logger.isDebugEnabled()) {
logger.debug(logMessage);
if (messageLogger.isDebugEnabled()) {
messageLogger.debug(logMessage);
}
break;
case TRACE:
if (logger.isTraceEnabled()) {
logger.trace(logMessage);
if (messageLogger.isTraceEnabled()) {
messageLogger.trace(logMessage);
}
break;
}

View File

@@ -384,7 +384,7 @@
Defines a message channel.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:ID" use="required" />
<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="scope" type="xsd:string" />
<xsd:attribute name="datatype" type="xsd:string">
<xsd:annotation>
@@ -517,7 +517,7 @@
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="optional" />
<xsd:attribute name="id" type="xsd:string" use="optional" />
<xsd:attribute name="service-interface" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation>
@@ -752,6 +752,15 @@ endpoint itself is a Polling Consumer for a channel with a queue.
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="logger-name" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Provide a name for the logger. This is useful when there are multiple logging Channel Adapters configured,
and you would like to differentiate them within the actual log. By default the logger name will be the
fully qualified class name of the LoggingHandler implementation.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="expression">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -816,7 +825,7 @@ endpoint itself is a Polling Consumer for a channel with a queue.
</xsd:attributeGroup>
<xsd:attributeGroup name="channelAdapterAttributes">
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
@@ -1125,7 +1134,7 @@ endpoint itself is a Polling Consumer for a channel with a queue.
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="basePollerType">
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="default" type="xsd:boolean" default="false" />
</xsd:extension>
</xsd:complexContent>
@@ -1307,7 +1316,7 @@ endpoint itself is a Polling Consumer for a channel with a queue.
<xsd:element name="selector" type="selectorType" />
<xsd:element ref="selector-chain" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="voting-strategy" default="ALL">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -2617,7 +2626,7 @@ Name of the header whose value will be used to route messages
Defines a Wire Tap Channel Interceptor.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:ID" use="optional" />
<xsd:attribute name="id" type="xsd:string" use="optional" />
<xsd:attribute name="channel" type="xsd:string" use="required">
<xsd:annotation>
<xsd:appinfo>
@@ -2795,7 +2804,7 @@ Name of the header whose value will be used to route messages
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="required" />
<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="default-channel" type="xsd:string" default="nullChannel">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -2966,7 +2975,7 @@ The list of component name patterns you want to track (e.g., tracked-components
</xsd:complexType>
<xsd:attributeGroup name="inputOutputChannelGroup">
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="output-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<logging-channel-adapter id="logger" logger-name="org.springframework.integration.test.logger"/>
</beans:beans>

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2002-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.config.xml;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.handler.LoggingHandler;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @since 2.0.6
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class LoggingChannelAdapterParserTests {
@Autowired
private LoggingHandler loggingHandler;
@Test
public void verifyLoggerName() {
assertEquals("org.springframework.integration.test.logger", TestUtils.getPropertyValue(loggingHandler, "messageLogger.name"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.