* Add `functions-support.adoc` chapter * Add more tests * Improve `InboundChannelAdapterAnnotationPostProcessor` to support Kotlin `Function0` * Add `FunctionsTests.kt` * Reformat Kotlin classes to use tabs * Upgrade to Kotlin `1.2.71` * Add `What's New` bullet Doc Polishing
116 lines
3.8 KiB
Plaintext
116 lines
3.8 KiB
Plaintext
[[logging-channel-adapter]]
|
|
=== Logging Channel Adapter
|
|
|
|
The `<logging-channel-adapter>` is often used in conjunction with a wire tap, as discussed in <<channel-wiretap>>.
|
|
However, it can also be used as the ultimate consumer of any flow.
|
|
For example, consider a flow that ends with a `<service-activator>` that returns a result, but you wish to discard that result.
|
|
To do that, you could send the result to `NullChannel`.
|
|
Alternatively, you can route it to an `INFO` level `<logging-channel-adapter>`.
|
|
That way, you can see the discarded message when logging at `INFO` level but not see it when logging at (for example) the `WARN` level.
|
|
With a `NullChannel`, you would see only the discarded message when logging at the `DEBUG` level.
|
|
The following listing shows all the possible attributes for the `logging-channel-adapter` element:
|
|
|
|
====
|
|
[source, xml]
|
|
----
|
|
|
|
<int:logging-channel-adapter
|
|
channel="" <1>
|
|
level="INFO" <2>
|
|
expression="" <3>
|
|
log-full-message="false" <4>
|
|
logger-name="" /> <5>
|
|
|
|
----
|
|
====
|
|
|
|
<1> The channel connecting the logging adapter to an upstream component.
|
|
<2> The logging level at which messages sent to this adapter will be logged.
|
|
Default: `INFO`.
|
|
<3> A SpEL expression representing exactly what parts of the message are logged.
|
|
Default: `payload` -- only the payload is logged.
|
|
if `log-full-message` is specified, this attribute cannot be specified.
|
|
<4> When `true`, the entire message (including headers) is logged.
|
|
Default: `false` -- only the payload is logged.
|
|
This attribute cannot be specified if `expression` is specified.
|
|
<5> Specifies the `name` of the logger (known as `category` in `log4j`).
|
|
Used to identify log messages created by this adapter.
|
|
This enables setting the log name (in the logging subsystem) for individual adapters.
|
|
By default, all adapters log under the following name: `org.springframework.integration.handler.LoggingHandler`.
|
|
|
|
==== Using Java Configuration
|
|
|
|
The following Spring Boot application shows an example of configuring the `LoggingHandler` by 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
|
|
@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);
|
|
|
|
}
|
|
|
|
}
|
|
----
|
|
====
|
|
|
|
==== Configuring with the Java DSL
|
|
|
|
The following Spring Boot application shows an example of configuring the logging channel adapter by using the Java DSL:
|
|
|
|
====
|
|
[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 IntegrationFlow loggingFlow() {
|
|
return IntegrationFlows.from(MyGateway.class)
|
|
.log(LoggingHandler.Level.DEBUG, "TEST_LOGGER",
|
|
m -> m.getHeaders().getId() + ": " + m.getPayload());
|
|
}
|
|
|
|
@MessagingGateway
|
|
public interface MyGateway {
|
|
|
|
void sendToLogger(String data);
|
|
|
|
}
|
|
|
|
}
|
|
----
|
|
====
|