INT-3977: Improve LoggingHandler for JavaConfig

JIRA: https://jira.spring.io/browse/INT-3977

* Add `Level` ctor
* Add `setLogExpression(Expression)` and `setLogExpressionString(String)`
* Deprecate existing `setExpression(String)` in favor of those new
* Some refactor for redundant code around `evaluationContext`
* Fix tests according a new `LoggingHandler` logic
* Add JavaConfig sample to the Reference Manual
This commit is contained in:
Artem Bilan
2016-04-05 12:19:27 -04:00
parent dee5c91bd8
commit c0b19e61b5
4 changed files with 108 additions and 17 deletions

View File

@@ -40,3 +40,44 @@ This attribute cannot be specified if `expression` is specified.
<5> Specifies the _name_ of the logger (known as `category` in `log4j`) used for log messages created by this adapter.
This enables setting the log name (in the logging subsystem) for individual adapters.
By default, all adapters will log under the name `org.springframework.integration.handler.LoggingHandler`.
==== Configuring with Java Configuration
The following Spring Boot application provides an example of configuring the `LoggingHandler` using Java configuration:
[source, java]
----
@SpringBootApplication
public class LoggingJavaApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context =
new SpringApplicationBuilder(LoggingJavaApplication.class)
.web(false)
.run(args);
MyGateway gateway = context.getBean(MyGateway.class);
gateway.sendToLogger("foo");
}
@Bean
public MessageChannel logInputChannel() {
return new DirectChannel();
}
@Bean
@ServiceActivator(inputChannel = "logChannel")
public LoggingHandler logging() {
LoggingHandler adapter = new LoggingHandler(LoggingHandler.Level.DEBUG);
adapter.setLoggerName("TEST_LOGGER");
adapter.setLogExpressionString("headers.id + ': ' + payload");
return adapter;
}
@MessagingGateway(defaultRequestChannel = "logChannel")
public interface MyGateway {
void sendToLogger(String data);
}
}
----