3

I would like to know how to utilize Log4J to log SOAP messages in WebSphere 7, I am using JAX-WS which uses AXIS2 engine that ships with WebSphere 7. I was able to log the SOAP messages using "tracing" in WebSphere but I would like to know if there is a way to use Log4J to log SOAP messages and use a File Appender.

I would appreciate if someone can tell me exactly how to configure it, I tried a few things but it did not work.

I did put log4j.properties file in WEB-INF/classes as follows but it does not log SOAP messages.

log4j.rootCategory=DEBUG, LOGFILE
log4j.logger.org.apache.axis2=DEBUG, LOGFILE
log4j.category.org.apache.axis2=DEBUG, LOGFILE
log4j.logger.org.apache.axis2.transport.http=DEBUG, LOGFILE
log4j.category.org.apache.axis2.transport.http=DEBUG, LOGFILE
log4j.logger.com.ibm.ws.websvcs=DEBUG, LOGFILE
log4j.category.com.ibm.ws.websvcs=DEBUG, LOGFILE

log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=C:/K1/logs/axis.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n
user3017924
  • 65
  • 1
  • 7
  • See if this question is relevant http://stackoverflow.com/questions/8131529/websphere-all-logs-are-going-to-systemout-log/ – dbreaux Feb 27 '14 at 23:10

2 Answers2

1

WebSphere web service runtime uses WebSphere trace logging internally. You likely won't be able to direct the built-in web service traces to log4j by simply adding and configuring log4j to your web service consuming application.

However, you can use a JAX-WS standard handler to log requests and responses or faults to a log4j Logger fairly easily (but you'll have to write some code).

Here a GlassFish tutorial on JAX-WS handlers. Note that the demonstration handler logs SOAP messages to System.out; you'll want to use log4j.

This StackOverflow post contains a full-java-class example of a SOAP message logging handler and how to register the handler programmatically so that it is executed during message processing. It too uses System.out; you'd need to substitute something like log.debug(...) for out.println(...) to use log4j. You could then configure log4j with a file appender for this logger as you attempted above.

As a sidebar, if you are obtaining your service reference via @WebServiceRef you can declaratively define a handler via XML file referenced by @HandlerChain. An end-to-end IBM tutorial is here.

Community
  • 1
  • 1
Scott Heaberlin
  • 3,364
  • 1
  • 23
  • 22
0

Configuring log4j is same as any other project. Make sure that log4j.xml or properties file is in the class path and log4j related jars.

can you post any errors or anything config files.

If you want to log the request and responses you create a SOAP handler to do it for you.

  • I added the above log4j.properties but it does not log SOAP messages, I placed it under WEB-INF/classes directory. Is any other configuration needed? – user3017924 Feb 25 '14 at 14:03
  • Do you see a axis.log file if not try to create it and restart the server. Please look for any errors when the appserver is starting. – Surendra Poranki Feb 25 '14 at 20:31
  • axis.log is there but it is empty, is the log4j configuration correct? Do I have correct level and package name? log4j.category.org.apache.axis2=DEBUG, LOGFILE ? – user3017924 Feb 26 '14 at 20:50
  • I do see this error ERROR Attempted to append to closed appender named [LOGFILE]. – user3017924 Feb 26 '14 at 22:03