John Oxley
John Oxley

Reputation: 15010

Specify logging level from message header - Spring Integration - Logging Channel Adapter

I have setup a logging channel adapter as shown.

<int:logging-channel-adapter id="logger" logger-name="messages" 
  expression="payload.toLogString()" level="????" />

For the level I want a SpEL expression that accomplishes the logic

if(headers.isSet("LoggingLevel"))
  level = headers.get("LoggingLevel);
else
  level = "INFO";

Preferably using the ternary operator.

Upvotes: 1

Views: 1727

Answers (1)

Gary Russell
Gary Russell

Reputation: 174799

There is not currently a way to dynamically set the log level for the logging channel adapter; please feel free to open an 'Improvement' JIRA issue here https://jira.springsource.org/browse/INT

In the meantime, you could work around it by defining multiple <logging-channel-adapter>s, each with a different level and use a <header-value-router> to route to the appropriate adapter.

You could encapsulate this in an <import>ed config file so you can reuse it in multiple apps.

Upvotes: 3

Related Questions