StevenPG
StevenPG

Reputation: 463

Alter default Spring Integration DirectChannel logging

Currently by default, Spring Integration writes debug logs in the format of:

DEBUG date time | producer-1 | o.s.i.c.DirectChannel | send line: 123 | 
preSend on channel 'myChannel', message: GenericMessage [payload=myPayload(), 
headers={content-length=XYZ, http_requestMethod=POST, errorChannel=errorChannel,
authorization=Bearer myExtremelyLongToken, replyChannel=replyChannel}]

The log example above seem fairly succinct, but when including a large JSON payload and many headers, it becomes unwieldy very quickly.

The largest contributor to this is the authorization header. This header can contain hundreds of characters that make it nearly impossible to have more than a single long message on a 80-width terminal.

Is there a method or is it possible to edit the DirectChannel logging to exclude the authorization header?

Ideally we don't love having the authorization token included repeatedly in the logs either, since they are production tokens.

I would have to believe there is some method of hiding some portions of these default logs.

Upvotes: 0

Views: 221

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121550

Well, it is not possible to filter out a content of the message before logging (yet): https://github.com/spring-projects/spring-integration/issues/3222.

However you ca stop having a DEBUG logging level for the org.springframework.integration, but rather use a Wire-Tap on the particular channels to catch their messages and send dump them into the LoggingHandler with custom category and specific setLogExpression to do somehing with the message before logging it. That expression may call some bean (using an @ operator) and with the #root as an argument which is the whole Message for logging. Only the result of that call is going to be logged. So, you are free to build any filtering logic in that target bean you are going to call from this expression!

See more info in docs:

Upvotes: 1

Related Questions