I am fairly new to the web services world but have knowledge of log4j
.
I need to implement a functionality which will send the log messages to a web service rather than to a file using web service appender.
I read by searching on Google that WebServiceAppender
is one of the log4j
class, but I couldn't verify this.
log4j.appender.CONSOLE=main.WSAppender
log4j.appender.CONSOLE.endpoint=http://localhost:8080/Logging/services/logging?wsdl
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%p [%t] %c{2} (%M:%L) :: %m%n
WSAppender.java extends AppenderSkeleton, can't resolve endpoint, hostname in append()
if (endpoint == null) {
System.out.println("no endpoint set. Check configuration file");
System.out.println("[" + hostname + "] " + this.layout.format(event));
return;
}
I suggest you have a look at this article: http://www.ibm.com/developerworks/webservices/library/ws-log4j/index.html
It specifically describes using the WebServiceAppender.
Ah, Google!
when you extend the class
AppenderSkeleton
I would assume that you should initialize your webservice class in thepublic void activateOptions()
method which you should override. I've written DatabaseAppender and JmsAppender log4j loggers and I've always found that I have to initialize the db connection or jms connection or in your case the webservice properties in thepublic void activateOptions()
method.Then as usual in the
append(LoggingEvent)
method you would just invoke the webservice.Might I suggest to implement a BlockingQueue to store all the LoggingEvent objects so that if you are getting an influx of log messages they are queued and sent to the webservice asynchronously.
Updated to include a Template Log4j Class
Try to use the below template. I added comments in important sections. Basically in the activateOptions and processEvent method is where you would initialize your "connection" and send your event objects. Can be DB, JMS, WebService ...etc.