Axis2 logging SOAP request and response with logback truncates to 4000 characters(bytes)

Viewed 1010

We are trying to log Axis2 SOAP log messages with logback and following configuration:

<!-- Axis client appender -->
<appender name="AxisLogging" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <filter class="ch.qos.logback.classic.filter.LevelFilter">
    <level>INFO</level>
    <OnMatch>ACCEPT</OnMatch>
    <OnMismatch>NEUTRAL</OnMismatch>
  </filter>
  <filter class="ch.qos.logback.classic.filter.LevelFilter">
    <level>DEBUG</level>
    <OnMatch>ACCEPT</OnMatch>
    <OnMismatch>NEUTRAL</OnMismatch>
  </filter>
  <filter class="ch.qos.logback.classic.filter.LevelFilter">
    <level>TRACE</level>
    <OnMatch>ACCEPT</OnMatch>
    <OnMismatch>DENY</OnMismatch>
  </filter>

  <File>log/axis-client.log</File>
  <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
    <FileNamePattern>log/axis-client.%i.log</FileNamePattern>
    <MinIndex>1</MinIndex>
    <MaxIndex>5</MaxIndex>
  </rollingPolicy>
  <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
    <MaxFileSize>100MB</MaxFileSize>
  </triggeringPolicy>

  <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>[%date{yyyy-MM-dd HH:mm:ss.SSS zZ}] %-5level [%mdc{requestsite}] [%mdc{session.id}] "%thread" %msg %ex%n</Pattern>
    </layout>
  </encoder>
</appender>

<logger name="httpclient.wire.content">
  <appender-ref ref="AxisLogging"/>
</logger>

And log messages of long request, and response XML are truncated on 4000 characters, and spreads through multiple log lines. Is there any way to configure logback to log whole XML in one log line?

Thanks!

2 Answers

Apperently this is issue with ReaderConfig.java (com.ctc.wstx.api.ReaderConfig.java) which is responsible for reading (and logging web service response). As you can see here:

https://github.com/FasterXML/woodstox/blob/master/src/main/java/com/ctc/wstx/api/ReaderConfig.java

In method createFullDefaults() which is called on server start by com.ctc.wstx.stax.WstxInputFactory, Reader is constructed with fixed buffer length of 4000.

So logging with custom code is only solution if you want full Axis2 response XML message in one line.

Are you sure the limit is in logback? Maybe the limitation is in axis2. Note: In this example the limitation is in the apache CXF library.

Text length limit in logback logging

This is how I usually log soap messages. Does require some programming though.

String request = stub._getServiceClient().getLastOperationContext().getMessageContext("Out")
              .getEnvelope().toString());
String response = stub._getServiceClient().getLastOperationContext().getMessageContext("In")
              .getEnvelope().toString());

If you write those vars to the log then you shouldn't have a problem.

Related