I know CXF can use either log4j or jul based on a JVM parameter but I ended up 
writing my own log4j logging interceptors because I also wanted to bump the 
level down to DEBUG:

// 2.5.0

public class Log4jLoggingInInterceptor extends LoggingInInterceptor {
    private static final Logger log = 
LogManager.getLogger(Log4jLoggingInInterceptor.class);    
    public Log4jLoggingInInterceptor() {
        setPrettyLogging(true);
    }
    @Override
    public void handleMessage(Message message) throws Fault {
        if (log.isDebugEnabled()) {
            super.handleMessage(message);
        }
    }    
    @Override
    protected void log(java.util.logging.Logger ignored, String message) {
        log.debug(message);
    }
}

Change your set*Logging methods to get the Log4jLogging*Interceptor loggers.



________________________________
 From: "Pieper, Aaron" <[email protected]>
To: [email protected] 
Sent: Wednesday, May 16, 2012 6:20 PM
Subject: Independently toggling inbound/outbound logging in CXF
 
Our web application currently uses Log4j and CXF 2.4.2, and has some
code to dynamically toggling inbound or outbound logging. This means
that while our web application is running, administrators can
temporarily enable inbound SOAP message logging, and then turn it back
off when they're done. The underlying code looks like this:

public void setInboundLogging(boolean b) {
  LogFactory.getLog(LoggingInInterceptor.class).setLevel(b ? Level.INFO
: Level.ERROR);
}

public void setOutboundLogging(boolean b) {
  LogFactory.getLog(LoggingOutInterceptor.class).setLevel(b ? Level.INFO
: Level.ERROR);
}

This worked in CXF 2.4.2, but breaks in CXF 2.5.3. This is because CXF
2.5.3 uses a more complex implementation of the logging interceptor
classes. Now, the LoggingInInterceptor and LoggingOutInterceptor classes
both use the
"org.apache.cxf.services.MyImplService.MyServiceImplPort.MyService"
logger, whereas before they both had separate loggers based on their
class name. Because the in and out interceptors share the same logger in
CXF 2.5.3, I can't think of a way to control them independently anymore.

I see two workarounds, one would be to implement our own in-house
logging interceptors which behave like the ones in CXF 2.4.2. Another
might be to create an in-house patch of CXF 2.5.3 which has an extra
"logName" on these interceptors...

<bean id="loggingInInterceptor"
class="org.apache.cxf.interceptor.LoggingInInterceptor">
  <property name="logName"
value="org.apache.cxf.interceptor.LoggingInInterceptor"/>
</bean>

Are there any other more intelligent ways to approach this problem?
Also, should I submit an improvement request to CXF's issue tracker
describing this use case?

Thanks,

- Aaron

Reply via email to