FileDocCategorySizeDatePackage
LogHandler.javaAPI DocApache Axis 1.44523Sat Apr 22 18:57:28 BST 2006org.apache.axis.handlers

LogHandler

public class LogHandler extends BasicHandler
A simple Handler which logs the request and response messages to either the console or a specified file (default "axis.log"). To use this, deploy it either in both the request and response flows (global, service, or transport) or in just the response flow. If deployed in both places, you'll also get an elapsed time indication, which can be handy for debugging.
author
Doug Davis (dug@us.ibm.com)
author
Glen Daniels (gdaniels@apache.org)

Fields Summary
protected static Log
log
long
start
private boolean
writeToConsole
private String
filename
Constructors Summary
Methods Summary
private java.io.PrintWritergetWriter()

        PrintWriter writer;

        // Allow config info to control where we write.
        if (writeToConsole) {
            // Writing to the console
            writer = new PrintWriter(System.out);
        } else {
            // Writing to a file.
            if (filename == null) {
                filename = "axis.log";
            }
            writer = new PrintWriter(new FileWriter( filename, true ));
        }
        return writer;
    
public voidinit()


       
        super.init();

        Object opt = this.getOption("LogHandler.writeToConsole");
        if (opt != null && opt instanceof String &&
                "true".equalsIgnoreCase((String)opt))
            writeToConsole = true;

        opt = this.getOption("LogHandler.fileName");
        if (opt != null && opt instanceof String)
            filename = (String)opt;
    
public voidinvoke(org.apache.axis.MessageContext msgContext)

        log.debug("Enter: LogHandler::invoke");
        if (msgContext.getPastPivot() == false) {
           start = System.currentTimeMillis();
        } else {
            logMessages(msgContext);
        }
        log.debug("Exit: LogHandler::invoke");
    
private voidlogMessages(org.apache.axis.MessageContext msgContext)

        try {
            PrintWriter writer   = null;

            writer = getWriter();

            Message inMsg = msgContext.getRequestMessage();
            Message outMsg = msgContext.getResponseMessage();

            writer.println( "=======================================================" );
            if (start != -1) {
                writer.println( "= " + Messages.getMessage("elapsed00",
                       "" + (System.currentTimeMillis() - start)));
            }
            writer.println( "= " + Messages.getMessage("inMsg00",
                   (inMsg == null ? "null" : inMsg.getSOAPPartAsString())));
            writer.println( "= " + Messages.getMessage("outMsg00",
                   (outMsg == null ? "null" : outMsg.getSOAPPartAsString())));
            writer.println( "=======================================================" );

            //START FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16646
            if (!writeToConsole) {
              writer.close();
            }
            //END FIX: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16646

        } catch( Exception e ) {
            log.error( Messages.getMessage("exception00"), e );
            throw AxisFault.makeFault(e);
        }
    
public voidonFault(org.apache.axis.MessageContext msgContext)

        try {
            logMessages(msgContext);
        } catch (AxisFault axisFault) {
            log.error(Messages.getMessage("exception00"), axisFault);
        }