Anything ever come of Ed's patch? "Tellman, Ed" <[EMAIL PROTECTED]> writes:
> The attached patch modifies the logging scheme to use the jakarta commons > logging package. > > I was originally planning to cache the logger once for each class or once > for each instance. Then I realized that this might make dynamically > changing the logging level, etc. at run time difficult, since copies of old > loggers might continue to hang around. Anyway, I opted for the following > scheme: > -- If a method is definitely going to use a logger, get the logger > from the factory at the beginning of the method > -- Otherwise, get the logger the first time it is used in a method. > > The logging factory caches loggers anyway, so getting a logger from the > factory, rather than caching it locally, shouldn't be too expensive, I > think, although I didn't do any measurements. > > I was going to make XmlRpc.setDebug() continue to work, by making it > configure the logging package to always print on the standard error stream. > However, I wasn't quite able to figure out how to make this happen. I'll > investigate further. If someone else has thoughts on how to do this, please > feel free to modify setDebug() accordingly. > > The logging-commons.jar file will need to be added to the lib directory. > The patch adds it to build.xml. > > I modified things that were printing exceptions on System.err to instead use > log.error(), except when they were in a main() method and printed a usage > message. > > I tested it with log4j, and it seems to work fine. I didn't try any of the > other logging options. > > Please let me know if there are any problems or suggestions. > > Thanks, > --Ed Tellman > [EMAIL PROTECTED] > > > -------------------- > This message (including any attachments) may contain confidential > information intended for a specific individual and purpose. If you are not > the intended recipient, delete this message. If you are not the intended > recipient, disclosing, copying, distributing, or taking any action based on > this message is strictly prohibited. > > > > Index: build.properties > =================================================================== > RCS file: /home/cvspublic/xml-rpc/build.properties,v > retrieving revision 1.9 > diff -u -r1.9 build.properties > --- build.properties 15 Aug 2002 16:30:04 -0000 1.9 > +++ build.properties 9 Dec 2002 15:49:09 -0000 > @@ -35,3 +35,5 @@ > jcert.jar = ${lib.repo}/jcert.jar > servlet.jar = ${lib.repo}/servlet.jar > junit.jar = ${lib.repo}/junit-3.7.jar > +commons-logging.jar = ${lib.repo}/commons-logging.jar > + > Index: build.xml > =================================================================== > RCS file: /home/cvspublic/xml-rpc/build.xml,v > retrieving revision 1.20 > diff -u -r1.20 build.xml > --- build.xml 10 Oct 2002 00:33:24 -0000 1.20 > +++ build.xml 9 Dec 2002 15:49:09 -0000 > @@ -18,6 +18,7 @@ > <pathelement location="${jcert.jar}"/> > <pathelement location="${servlet.jar}"/> > <pathelement location="${junit.jar}"/> > + <pathelement location="${commons-logging.jar}"/> > </path> > > <!-- ================================================================== --> > @@ -32,6 +33,7 @@ > <echo message="jcert.jar = ${jcert.jar}"/> > <echo message="servlet.jar = ${servlet.jar}"/> > <echo message="junit.jar = ${junit.jar}"/> > + <echo message="commons-logging.jar = ${commons-logging.jar}"/> > </target> > > <!-- ================================================================== --> > Index: examples/echo/AsyncClient.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/examples/echo/AsyncClient.java,v > retrieving revision 1.1 > diff -u -r1.1 AsyncClient.java > --- examples/echo/AsyncClient.java 8 Nov 2001 18:21:31 -0000 1.1 > +++ examples/echo/AsyncClient.java 9 Dec 2002 15:49:10 -0000 > @@ -54,6 +54,7 @@ > */ > > > +import org.apache.commons.logging.LogFactory; > import org.apache.xmlrpc.*; > import java.util.Vector; > import java.net.URL; > @@ -115,7 +116,7 @@ > * something went wrong during XML-RPC call. > */ > public void handleError (Exception exception, URL url, String method) { > - System.err.println ("Error: "+exception); > + LogFactory.getLog(AsyncClient.class).error("Error: " + exception); > } > > } > Index: src/java/org/apache/xmlrpc/Invoker.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/Invoker.java,v > retrieving revision 1.1 > diff -u -r1.1 Invoker.java > --- src/java/org/apache/xmlrpc/Invoker.java 27 Aug 2002 19:20:41 -0000 1.1 > +++ src/java/org/apache/xmlrpc/Invoker.java 9 Dec 2002 15:49:09 -0000 > @@ -59,6 +59,9 @@ > import java.lang.reflect.Method; > import java.util.Vector; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > /** > * Introspects handlers using Java Reflection to call methods matching > * a XML-RPC call. > @@ -77,10 +80,8 @@ > invokeTarget = target; > targetClass = (invokeTarget instanceof Class) ? (Class) invokeTarget : > invokeTarget.getClass(); > - if (XmlRpc.debug) > - { > - System.out.println("Target object is " + targetClass); > - } > + LogFactory.getLog(Invoker.class).debug( > + "Target object is " + targetClass); > } > > /** > @@ -88,6 +89,8 @@ > */ > public Object execute(String methodName, Vector params) throws Exception > { > + Log log = LogFactory.getLog(Invoker.class); > + > // Array mit Classtype bilden, ObjectAry mit Values bilden > Class[] argClasses = null; > Object[] argValues = null; > @@ -128,13 +131,14 @@ > methodName = methodName.substring(dot + 1); > } > > - if (XmlRpc.debug) > + > + if (log.isDebugEnabled()) > { > - System.out.println("Searching for method: " + methodName + > - " in class " + targetClass.getName()); > + log.debug("Searching for method: " + methodName + > + " in class " + targetClass.getName()); > for (int i = 0; i < argClasses.length; i++) > { > - System.out.println("Parameter " + i + ": " + argValues[i] > + log.debug("Parameter " + i + ": " + argValues[i] > + " (" + argClasses[i] + ')'); > } > } > @@ -177,10 +181,8 @@ > } > catch(InvocationTargetException it_e) > { > - if (XmlRpc.debug) > - { > - it_e.getTargetException().printStackTrace(); > - } > + log.error(it_e.getTargetException().getStackTrace()); > + > // check whether the thrown exception is XmlRpcException > Throwable t = it_e.getTargetException(); > if (t instanceof XmlRpcException) > Index: src/java/org/apache/xmlrpc/LiteXmlRpcTransport.java > =================================================================== > RCS file: >/home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/LiteXmlRpcTransport.java,v > retrieving revision 1.1 > diff -u -r1.1 LiteXmlRpcTransport.java > --- src/java/org/apache/xmlrpc/LiteXmlRpcTransport.java 5 Dec 2002 08:49:24 >-0000 1.1 > +++ src/java/org/apache/xmlrpc/LiteXmlRpcTransport.java 9 Dec 2002 15:49:09 >-0000 > @@ -66,6 +66,9 @@ > import java.util.Vector; > import java.util.StringTokenizer; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > /** > * Interface from XML-RPC to a 'lite' HTTP implementation. This class will use > * the XmlRpcClientLite.auth member for the HTTP Basic authentication string. > @@ -161,10 +164,7 @@ > { > // same as above, but exception has to be converted to > // IOException. > - if (XmlRpc.debug) > - { > - x.printStackTrace (); > - } > + LogFactory.getLog(LiteXmlRpcTransport.class).error(x.getStackTrace()); > > String msg = x.getMessage (); > if (msg == null || msg.length () == 0) > @@ -212,6 +212,8 @@ > */ > public InputStream sendRequest(byte[] request) throws IOException > { > + Log log = LogFactory.getLog(LiteXmlRpcTransport.class); > + > output.write(("POST " + uri + " HTTP/1.0\r\n").getBytes()); > output.write(("User-Agent: " + XmlRpc.version + "\r\n").getBytes()); > output.write(("Host: " + host + "\r\n").getBytes()); > @@ -233,10 +235,8 @@ > > // start reading server response headers > String line = readLine(); > - if (XmlRpc.debug) > - { > - System.out.println(line); > - } > + log.debug(line); > + > int contentLength = -1; > try > { > @@ -258,7 +258,7 @@ > } > catch (Exception x) > { > - // x.printStackTrace (); > + log.error(x.getStackTrace()); > throw new IOException("Server returned invalid Response."); > } > do > @@ -266,10 +266,7 @@ > line = readLine (); > if (line != null) > { > - if (XmlRpc.debug) > - { > - System.out.println(line); > - } > + log.debug(line); > line = line.toLowerCase(); > if (line.startsWith("content-length:")) > { > Index: src/java/org/apache/xmlrpc/WebServer.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/WebServer.java,v > retrieving revision 1.22 > diff -u -r1.22 WebServer.java > --- src/java/org/apache/xmlrpc/WebServer.java 3 Dec 2002 17:22:26 -0000 1.22 > +++ src/java/org/apache/xmlrpc/WebServer.java 9 Dec 2002 15:49:09 -0000 > @@ -70,6 +70,9 @@ > import java.util.StringTokenizer; > import java.util.Vector; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > /** > * A minimal web server that exclusively handles XML-RPC requests. > * > @@ -251,6 +254,8 @@ > private synchronized void setupServerSocket(int backlog) > throws Exception > { > + Log log = LogFactory.getLog(WebServer.class); > + > // Since we can't reliably set SO_REUSEADDR until JDK 1.4 is > // the standard, try to (re-)open the server socket several > // times. Some OSes (Linux and Solaris, for example), hold on > @@ -275,7 +280,7 @@ > } > } > > - if (XmlRpc.debug) > + if (log.isDebugEnabled()) > { > StringBuffer msg = new StringBuffer(); > msg.append("Opened XML-RPC server socket for "); > @@ -285,7 +290,7 @@ > { > msg.append(" after ").append(attempt).append(" tries"); > } > - System.out.println(msg.toString()); > + log.debug(msg.toString()); > } > > // A socket timeout must be set. > @@ -465,6 +470,7 @@ > */ > public void run() > { > + Log log = LogFactory.getLog(WebServer.class); > try > { > setupServerSocket(50); > @@ -472,7 +478,7 @@ > catch (Exception e) > { > listener = null; > - e.printStackTrace(); > + log.error(e.getStackTrace()); > throw new RuntimeException(e.getMessage()); > } > > @@ -489,7 +495,7 @@ > } > catch (SocketException socketOptEx) > { > - System.err.println(socketOptEx); > + log.error(socketOptEx); > } > > if (allowConnection(socket)) > @@ -509,29 +515,23 @@ > } > catch (Exception ex) > { > - System.err.println("Exception in XML-RPC listener loop (" > + log.error("Exception in XML-RPC listener loop (" > + ex + ")."); > - if (XmlRpc.debug) > - { > - ex.printStackTrace(); > - } > + log.error(ex.getStackTrace()); > } > catch (Error err) > { > - System.err.println("Error in XML-RPC listener loop (" > + log.error("Error in XML-RPC listener loop (" > + err + ")."); > - err.printStackTrace(); > + log.error(err.getStackTrace()); > } > } > } > catch (Exception exception) > { > - System.err.println("Error accepting XML-RPC connections (" > + log.error("Error accepting XML-RPC connections (" > + exception + ")."); > - if (XmlRpc.debug) > - { > - exception.printStackTrace(); > - } > + log.error(exception.getStackTrace()); > } > finally > { > @@ -540,15 +540,12 @@ > try > { > serverSocket.close(); > - if (XmlRpc.debug) > - { > - System.out.print("Closed XML-RPC server socket"); > - } > + log.debug("Closed XML-RPC server socket"); > serverSocket = null; > } > catch (IOException e) > { > - e.printStackTrace(); > + log.error(e.getStackTrace()); > } > } > > @@ -563,8 +560,8 @@ > } > catch (Exception e) > { > - System.err.println(e); > - e.printStackTrace(); > + log.error(e); > + log.error(e.getStackTrace()); > } > } > } > @@ -708,6 +705,7 @@ > */ > public void run() > { > + Log log = LogFactory.getLog(WebServer.class); > try > { > boolean keepAlive = false; > @@ -723,10 +721,8 @@ > { > line = readLine(); > } > - if (XmlRpc.debug) > - { > - System.out.println(line); > - } > + log.debug(line); > + > int contentLength = -1; > > // tokenize first line of HTTP request > @@ -741,10 +737,8 @@ > line = readLine(); > if (line != null) > { > - if (XmlRpc.debug) > - { > - System.out.println(line); > - } > + log.debug(line); > + > String lineLower = line.toLowerCase(); > if (lineLower.startsWith("content-length:")) > { > @@ -790,11 +784,7 @@ > } > catch (Exception exception) > { > - System.err.println(exception); > - if (XmlRpc.debug) > - { > - exception.printStackTrace(); > - } > + log.error(exception.getStackTrace()); > } > finally > { > Index: src/java/org/apache/xmlrpc/XmlRpc.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/XmlRpc.java,v > retrieving revision 1.35 > diff -u -r1.35 XmlRpc.java > --- src/java/org/apache/xmlrpc/XmlRpc.java 21 Nov 2002 01:28:16 -0000 1.35 > +++ src/java/org/apache/xmlrpc/XmlRpc.java 9 Dec 2002 15:49:09 -0000 > @@ -59,6 +59,12 @@ > import java.util.Hashtable; > import java.util.Stack; > import java.util.Vector; > +import java.util.logging.Logger; > + > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > +import org.apache.commons.logging.LogSource; > +import org.apache.commons.logging.impl.SimpleLog; > import org.xml.sax.AttributeList; > import org.xml.sax.HandlerBase; > import org.xml.sax.InputSource; > @@ -161,11 +167,6 @@ > static boolean keepalive = false; > > /** > - * Whether to log debugging output. > - */ > - public static boolean debug = false; > - > - /** > * The list of valid XML elements used for RPC. > */ > final static String types[] = > @@ -248,9 +249,10 @@ > } > catch (Exception e) > { > - System.err.println("Unable to create configured TypeFactory '" + > - typeFactory.getName() + "': " + e.getMessage() + > - ": Using default"); > + LogFactory.getLog(XmlRpc.class).error( > + "Unable to create configured TypeFactory '" + > + typeFactory.getName() + "': " + e.getMessage() + > + ": Using default"); > // Call self recursively to acquire default. > return createTypeFactory(null); > } > @@ -334,11 +336,17 @@ > } > > /** > - * Switch debugging output on/off. > - */ > + * Does nothing. Configure the log system with the jakarta > + * commons logging package.<p> > + * > + * See http://jakarta.apache.org/commons/logging.html for more information. > + * > + * @param val ignored > + * > + * @deprecated > + **/ > public static void setDebug(boolean val) > { > - debug = val; > } > > /** > @@ -363,6 +371,8 @@ > */ > synchronized void parse(InputStream is) throws Exception > { > + Log log = LogFactory.getLog(XmlRpc.class); > + > // reset values (XmlRpc objects are reusable) > errorLevel = NONE; > errorMsg = null; > @@ -410,10 +420,8 @@ > parser.setDocumentHandler(this); > parser.setErrorHandler(this); > > - if (debug) > - { > - System.out.println("Beginning parsing XML input stream"); > - } > + log.debug("Beginning parsing XML input stream"); > + > try > { > parser.parse(new InputSource (is)); > @@ -428,11 +436,9 @@ > cdata = null; > } > } > - if (debug) > - { > - System.out.println ("Spent " + (System.currentTimeMillis() - now) > - + " millis parsing"); > - } > + > + log.debug("Spent " + (System.currentTimeMillis() - now) > + + " millis parsing"); > } > > /** > @@ -463,11 +469,7 @@ > */ > public void endElement(String name) throws SAXException > { > - > - if (debug) > - { > - System.out.println("endElement: " + name); > - } > + LogFactory.getLog(XmlRpc.class).debug("endElement: " + name); > > // finalize character data, if appropriate > if (currentValue != null && readCdata) > @@ -526,10 +528,7 @@ > public void startElement(String name, AttributeList atts) > throws SAXException > { > - if (debug) > - { > - System.out.println("startElement: " + name); > - } > + LogFactory.getLog(XmlRpc.class).debug("startElement: " + name); > > if ("value".equals(name)) > { > @@ -603,7 +602,7 @@ > */ > public void error(SAXParseException e) throws SAXException > { > - System.err.println("Error parsing XML: " + e); > + LogFactory.getLog(XmlRpc.class).error("Error parsing XML: " + e); > errorLevel = RECOVERABLE; > errorMsg = e.toString(); > } > @@ -615,7 +614,7 @@ > */ > public void fatalError(SAXParseException e) throws SAXException > { > - System.err.println("Fatal error parsing XML: " + e); > + LogFactory.getLog(XmlRpc.class).error("Fatal error parsing XML: " + e); > errorLevel = FATAL; > errorMsg = e.toString(); > } > Index: src/java/org/apache/xmlrpc/XmlRpcClient.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcClient.java,v > retrieving revision 1.15 > diff -u -r1.15 XmlRpcClient.java > --- src/java/org/apache/xmlrpc/XmlRpcClient.java 5 Dec 2002 08:49:24 -0000 > 1.15 > +++ src/java/org/apache/xmlrpc/XmlRpcClient.java 9 Dec 2002 15:49:09 -0000 > @@ -66,6 +66,9 @@ > import java.util.Hashtable; > import java.util.Stack; > import java.util.Vector; > + > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > import org.xml.sax.AttributeList; > import org.xml.sax.SAXException; > > @@ -109,10 +112,8 @@ > public XmlRpcClient(URL url) > { > this.url = url; > - if (XmlRpc.debug) > - { > - System.out.println("Created client to url space " + url); > - } > + LogFactory.getLog(XmlRpcClient.class).debug( > + "Created client to url space " + url); > } > > /** > Index: src/java/org/apache/xmlrpc/XmlRpcClientWorker.java > =================================================================== > RCS file: >/home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcClientWorker.java,v > retrieving revision 1.1 > diff -u -r1.1 XmlRpcClientWorker.java > --- src/java/org/apache/xmlrpc/XmlRpcClientWorker.java 5 Dec 2002 08:49:24 >-0000 1.1 > +++ src/java/org/apache/xmlrpc/XmlRpcClientWorker.java 9 Dec 2002 15:49:09 >-0000 > @@ -58,6 +58,9 @@ > import java.io.InputStream; > import java.io.IOException; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > /** > * Tie together the XmlRequestProcessor and XmlResponseProcessor to handle > * a request serially in a single thread. > @@ -88,9 +91,10 @@ > throws XmlRpcException, XmlRpcClientException, IOException > { > long now = 0; > - Object response; > + Object response; > + Log log = LogFactory.getLog(XmlRpcClientWorker.class); > > - if (XmlRpc.debug) > + if (log.isDebugEnabled()); > { > now = System.currentTimeMillis(); > } > @@ -123,19 +127,13 @@ > } > catch (Exception x) > { > - if (XmlRpc.debug) > - { > - x.printStackTrace(); > - } > + log.error(x.getStackTrace()); > throw new XmlRpcClientException("Unexpected exception in client >processing.", x); > } > finally > { > - if (XmlRpc.debug) > - { > - System.out.println("Spent " + (System.currentTimeMillis() - now) > - + " millis in request/process/response"); > - } > + log.debug("Spent " + (System.currentTimeMillis() - now) > + + " millis in request/process/response"); > } > } > > Index: src/java/org/apache/xmlrpc/XmlRpcRequestProcessor.java > =================================================================== > RCS file: >/home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcRequestProcessor.java,v > retrieving revision 1.5 > diff -u -r1.5 XmlRpcRequestProcessor.java > --- src/java/org/apache/xmlrpc/XmlRpcRequestProcessor.java 5 Dec 2002 08:49:24 >-0000 1.5 > +++ src/java/org/apache/xmlrpc/XmlRpcRequestProcessor.java 9 Dec 2002 15:49:09 >-0000 > @@ -58,6 +58,9 @@ > import java.io.InputStream; > import java.util.Vector; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > /** > * Process an InputStream and produce an XmlRpcServerRequest. This class > * is NOT thread safe. > @@ -90,12 +93,15 @@ > */ > public XmlRpcServerRequest decodeRequest(InputStream is) > { > + Log log = LogFactory.getLog(XmlRpcRequestProcessor.class); > long now = 0; > > - if (XmlRpc.debug) > + if (log.isDebugEnabled()) > { > now = System.currentTimeMillis(); > + log.debug("start decode at: " + now); > } > + > try > { > try > @@ -106,11 +112,10 @@ > { > throw new ParseFailed(e); > } > - if (XmlRpc.debug) > - { > - System.out.println("XML-RPC method name: " + methodName); > - System.out.println("Request parameters: " + requestParams); > - } > + > + log.debug("XML-RPC method name: " + methodName); > + log.debug("Request parameters: " + requestParams); > + > // check for errors from the XML parser > if (errorLevel > NONE) > { > @@ -122,11 +127,8 @@ > finally > { > requestParams.removeAllElements(); > - if (XmlRpc.debug) > - { > - System.out.println("Spent " + (System.currentTimeMillis() - now) > + log.debug("Spent " + (System.currentTimeMillis() - now) > + " millis decoding request"); > - } > } > } > > Index: src/java/org/apache/xmlrpc/XmlRpcResponseProcessor.java > =================================================================== > RCS file: >/home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcResponseProcessor.java,v > retrieving revision 1.2 > diff -u -r1.2 XmlRpcResponseProcessor.java > --- src/java/org/apache/xmlrpc/XmlRpcResponseProcessor.java 5 Dec 2002 08:49:24 >-0000 1.2 > +++ src/java/org/apache/xmlrpc/XmlRpcResponseProcessor.java 9 Dec 2002 15:49:09 >-0000 > @@ -60,6 +60,9 @@ > import java.io.IOException; > import java.util.Hashtable; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > /** > * Process an Object and produce byte array that represents the specified > * encoding of the output as an XML-RPC response. This is NOT thread safe. > @@ -85,9 +88,13 @@ > throws IOException, UnsupportedEncodingException, XmlRpcException > { > long now = 0; > - if (XmlRpc.debug) > + > + Log log = LogFactory.getLog(XmlRpcResponseProcessor.class); > + if (log.isDebugEnabled()) > { > now = System.currentTimeMillis(); > + log.debug("starting encoding response at: " + > + System.currentTimeMillis()); > } > > try > @@ -100,11 +107,8 @@ > } > finally > { > - if (XmlRpc.debug) > - { > - System.out.println("Spent " + (System.currentTimeMillis() - now) > + log.debug("Spent " + (System.currentTimeMillis() - now) > + " millis encoding response"); > - } > } > } > > @@ -118,10 +122,9 @@ > */ > public byte[] encodeException(Exception x, String encoding) > { > - if (XmlRpc.debug) > - { > - x.printStackTrace(); > - } > + Log log = LogFactory.getLog(XmlRpcResponseProcessor.class); > + log.debug(x.getStackTrace()); > + > // Ensure that if there is anything in the buffer, it > // is cleared before continuing with the writing of exceptions. > // It is possible that something is in the buffer > @@ -136,14 +139,14 @@ > } > catch (UnsupportedEncodingException encx) > { > - System.err.println("XmlRpcServer attempted to use " > + log.error("XmlRpcServer attempted to use " > + "unsupported encoding: " + encx); > // NOTE: If we weren't already using the default > // encoding, we could try it here. > } > catch (IOException iox) > { > - System.err.println("XmlRpcServer experienced I/O error " > + log.error("XmlRpcServer experienced I/O error " > + "writing error response: " + iox); > } > > @@ -160,7 +163,7 @@ > { > // Unlikely to occur, as we just sent a struct > // with an int and a string. > - System.err.println("Unable to send error response to " > + log.error("Unable to send error response to " > + "client: " + e); > } > > Index: src/java/org/apache/xmlrpc/XmlRpcServer.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcServer.java,v > retrieving revision 1.35 > diff -u -r1.35 XmlRpcServer.java > --- src/java/org/apache/xmlrpc/XmlRpcServer.java 21 Oct 2002 13:08:50 -0000 > 1.35 > +++ src/java/org/apache/xmlrpc/XmlRpcServer.java 9 Dec 2002 15:49:10 -0000 > @@ -60,6 +60,8 @@ > import java.util.EmptyStackException; > import java.util.Stack; > > +import org.apache.commons.logging.LogFactory; > + > /** > * A multithreaded, reusable XML-RPC server object. The name may be misleading > * because this does not open any server sockets. Instead it is fed by passing > @@ -172,7 +174,8 @@ > nbrWorkers += 1; > if (nbrWorkers >= maxThreads * .95) > { > - System.out.println("95% of XML-RPC server threads in use"); > + LogFactory.getLog(XmlRpcServer.class).warn( > + "95% of XML-RPC server threads in use"); > } > return createWorker(); > } > Index: src/java/org/apache/xmlrpc/XmlRpcWorker.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcWorker.java,v > retrieving revision 1.5 > diff -u -r1.5 XmlRpcWorker.java > --- src/java/org/apache/xmlrpc/XmlRpcWorker.java 5 Dec 2002 08:49:24 -0000 > 1.5 > +++ src/java/org/apache/xmlrpc/XmlRpcWorker.java 9 Dec 2002 15:49:09 -0000 > @@ -58,6 +58,9 @@ > import java.io.InputStream; > import java.io.IOException; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > /** > * Tie together the XmlRequestProcessor and XmlResponseProcessor to handle > * a request serially in a single thread. > @@ -101,10 +104,11 @@ > throws Exception > { > long now = 0; > + Log log = LogFactory.getLog(XmlRpcWorker.class); > > try > { > - if (XmlRpc.debug) > + if (log.isDebugEnabled()) > { > now = System.currentTimeMillis(); > } > @@ -138,11 +142,8 @@ > } > finally > { > - if (XmlRpc.debug) > - { > - System.out.println("Spent " + (System.currentTimeMillis() - now) > - + " millis processing request"); > - } > + log.debug("Spent " + (System.currentTimeMillis() - now) > + + " millis processing request"); > } > } > > @@ -170,9 +171,10 @@ > */ > public byte[] execute(InputStream is, XmlRpcContext context) > { > + Log log = LogFactory.getLog(XmlRpcWorker.class); > long now = 0; > - > - if (XmlRpc.debug) > + > + if (log.isDebugEnabled()) > { > now = System.currentTimeMillis(); > } > @@ -196,20 +198,14 @@ > } > catch (Exception x) > { > - if (XmlRpc.debug) > - { > - x.printStackTrace(); > - } > + log.error(x.getStackTrace()); > return responseProcessor.encodeException > (x, requestProcessor.getEncoding()); > } > finally > { > - if (XmlRpc.debug) > - { > - System.out.println("Spent " + (System.currentTimeMillis() - now) > - + " millis in request/process/response"); > - } > + log.debug("Spent " + (System.currentTimeMillis() - now) > + + " millis in request/process/response"); > } > } > > Index: src/java/org/apache/xmlrpc/applet/JSXmlRpcApplet.java > =================================================================== > RCS file: >/home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/applet/JSXmlRpcApplet.java,v > retrieving revision 1.3 > diff -u -r1.3 JSXmlRpcApplet.java > --- src/java/org/apache/xmlrpc/applet/JSXmlRpcApplet.java 20 Mar 2002 15:11:03 >-0000 1.3 > +++ src/java/org/apache/xmlrpc/applet/JSXmlRpcApplet.java 9 Dec 2002 15:49:10 >-0000 > @@ -59,6 +59,8 @@ > import java.util.Hashtable; > import java.util.Vector; > > +import org.apache.commons.logging.LogFactory; > + > > /** > * An applet that can be accessed via LiveConnect from JavaScript. It provides > @@ -90,7 +92,8 @@ > initClient(); > arguments = new Vector(); > loaded = Boolean.TRUE; > - System.out.println("JSXmlRpcApplet initialized"); > + LogFactory.getLog(JSXmlRpcApplet.class).info( > + "JSXmlRpcApplet initialized"); > } > > // add ints (primitve != object) to structs, vectors > Index: src/java/org/apache/xmlrpc/applet/SimpleXmlRpcClient.java > =================================================================== > RCS file: >/home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/applet/SimpleXmlRpcClient.java,v > retrieving revision 1.5 > diff -u -r1.5 SimpleXmlRpcClient.java > --- src/java/org/apache/xmlrpc/applet/SimpleXmlRpcClient.java 7 Aug 2002 17:35:39 >-0000 1.5 > +++ src/java/org/apache/xmlrpc/applet/SimpleXmlRpcClient.java 9 Dec 2002 15:49:10 >-0000 > @@ -71,6 +71,9 @@ > import java.util.Hashtable; > import java.util.Stack; > import java.util.Vector; > + > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > import org.apache.xmlrpc.Base64; > import org.xml.sax.AttributeList; > import org.xml.sax.HandlerBase; > @@ -163,8 +166,7 @@ > static final int STRUCT = 6; > static final int ARRAY = 7; > > - // for debugging output > - public static boolean debug = false; > + > final static String types[] = {"String", "Integer", "Boolean", "Double", > "Date", "Base64", "Struct", "Array"}; > > @@ -179,11 +181,17 @@ > } > > /** > - * Switch debugging output on/off. > - */ > + * Does nothing. Configure the log system with the jakarta > + * commons logging package.<p> > + * > + * See http://jakarta.apache.org/commons/logging.html for more information. > + * > + * @param val ignored > + * > + * @deprecated > + **/ > public static void setDebug(boolean val) > { > - debug = val; > } > > /** > @@ -200,11 +208,8 @@ > > parser.parse(new InputSource(is)); > > - if (debug) > - { > - System.out.println("Spent " + (System.currentTimeMillis() - now) > - + " parsing"); > - } > + LogFactory.getLog(SimpleXmlRpcClient.class).debug( > + "Spent " + (System.currentTimeMillis() - now) + " parsing"); > } > > /** > @@ -298,6 +303,7 @@ > public Object execute(String method, Vector arguments) > throws XmlRpcException, IOException > { > + Log log = LogFactory.getLog(SimpleXmlRpcClient.class); > fault = false; > long now = System.currentTimeMillis(); > try > @@ -320,11 +326,11 @@ > out.flush(); > InputStream in = con.getInputStream(); > parse(in); > - System.out.println("result = " + result); > + log.debug("result = " + result); > } > catch (Exception x) > { > - x.printStackTrace(); > + log.error(x.getStackTrace()); > throw new IOException(x.getMessage()); > } > if (fault) > @@ -344,7 +350,7 @@ > } > throw exception; > } > - System.out.println("Spent " + (System.currentTimeMillis() - now) > + log.debug("Spent " + (System.currentTimeMillis() - now) > + " in request"); > return result; > } > @@ -400,10 +406,7 @@ > */ > public void endElement(String name) throws SAXException > { > - if (debug) > - { > - System.err.println("endElement: " + name); > - } > + LogFactory.getLog(SimpleXmlRpcClient.class).debug("endElement: " + name); > > // finalize character data, if appropriate > if (currentValue != null && readCdata) > @@ -460,10 +463,7 @@ > public void startElement (String name, AttributeList atts) > throws SAXException > { > - if (debug) > - { > - System.err.println("startElement: " + name); > - } > + LogFactory.getLog(SimpleXmlRpcClient.class).debug("startElement: " + name); > > if ("value".equals(name)) > { > @@ -538,7 +538,8 @@ > */ > public void error(SAXParseException e) throws SAXException > { > - System.err.println("Error parsing XML: " + e); > + LogFactory.getLog(SimpleXmlRpcClient.class).error( > + "Error parsing XML: " + e); > // errorLevel = RECOVERABLE; > // errorMsg = e.toString (); > } > @@ -550,7 +551,8 @@ > */ > public void fatalError(SAXParseException e) throws SAXException > { > - System.err.println("Fatal error parsing XML: " + e); > + LogFactory.getLog(SimpleXmlRpcClient.class).error( > + "Fatal error parsing XML: " + e); > // errorLevel = FATAL; > // errorMsg = e.toString (); > } > Index: src/java/org/apache/xmlrpc/applet/XmlRpcApplet.java > =================================================================== > RCS file: >/home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/applet/XmlRpcApplet.java,v > retrieving revision 1.2 > diff -u -r1.2 XmlRpcApplet.java > --- src/java/org/apache/xmlrpc/applet/XmlRpcApplet.java 20 Mar 2002 15:11:03 >-0000 1.2 > +++ src/java/org/apache/xmlrpc/applet/XmlRpcApplet.java 9 Dec 2002 15:49:10 >-0000 > @@ -61,6 +61,9 @@ > import java.net.URL; > import java.util.Vector; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > > /** > * An applet that provides basic XML-RPC client functionality. > @@ -89,7 +92,8 @@ > } > catch (NumberFormatException nfx) > { > - System.out.println("Error parsing port: " + nfx); > + LogFactory.getLog(XmlRpcApplet.class).error( > + "Error parsing port: " + nfx); > } > } > initClient(port); > @@ -119,16 +123,18 @@ > */ > public void initClient(int port, String uri) > { > + Log log = LogFactory.getLog(XmlRpcApplet.class); > + > String host = getCodeBase().getHost(); > try > { > URL url = new URL("http://" + host + ":" + port + uri); > - System.out.println("XML-RPC URL: " + url); > + log.info("XML-RPC URL: " + url); > client = new SimpleXmlRpcClient(url); > } > catch (MalformedURLException unlikely) > { > - System.out.println("Error constructing XML-RPC client for " > + log.error("Error constructing XML-RPC client for " > + host + ":" + port + ": " + unlikely); > } > } > Index: src/java/org/apache/xmlrpc/fesi/FesiRpcUtil.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/src/java/org/apache/xmlrpc/fesi/FesiRpcUtil.java,v > retrieving revision 1.2 > diff -u -r1.2 FesiRpcUtil.java > --- src/java/org/apache/xmlrpc/fesi/FesiRpcUtil.java 20 Mar 2002 15:11:04 -0000 > 1.2 > +++ src/java/org/apache/xmlrpc/fesi/FesiRpcUtil.java 9 Dec 2002 15:49:10 -0000 > @@ -72,7 +72,11 @@ > import java.util.Enumeration; > import java.util.Hashtable; > import java.util.Vector; > + > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > import org.apache.xmlrpc.XmlRpc; > +import org.apache.xmlrpc.XmlRpcWorker; > > /** > * > @@ -137,10 +141,9 @@ > // convert a JavaScript Object object to a generic Java. > public static Object convertE2J(ESValue what) throws EcmaScriptException > { > - if (XmlRpc.debug) > - { > - System.out.println("converting e-2-j: " + what.getClass()); > - } > + Log log = LogFactory.getLog(FesiRpcUtil.class); > + log.debug("converting e-2-j: " + what.getClass()); > + > if (what instanceof ESNull) > { > return null; > @@ -164,10 +167,7 @@ > for (Enumeration e = o.getProperties(); e.hasMoreElements();) > { > String next = (String) e.nextElement(); > - if (XmlRpc.debug) > - { > - System.out.println("converting object member " + next); > - } > + log.debug("converting object member " + next); > Object nj = convertE2J(o.getProperty(next, next.hashCode())); > if (nj != null)// can't put null as value in hashtable > { > Index: src/test/org/apache/xmlrpc/AsyncBenchmark.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/src/test/org/apache/xmlrpc/AsyncBenchmark.java,v > retrieving revision 1.1.1.1 > diff -u -r1.1.1.1 AsyncBenchmark.java > --- src/test/org/apache/xmlrpc/AsyncBenchmark.java 20 Jul 2001 19:38:20 -0000 > 1.1.1.1 > +++ src/test/org/apache/xmlrpc/AsyncBenchmark.java 9 Dec 2002 15:49:10 -0000 > @@ -59,6 +59,9 @@ > import java.io.IOException; > import java.net.URL; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > public class AsyncBenchmark > implements Runnable > { > @@ -152,8 +155,11 @@ > public synchronized void handleError (Exception exception, > URL url, String method) > { > - System.err.println (exception); > - exception.printStackTrace (); > + Log log = LogFactory.getLog(AsyncBenchmark.class); > + > + log.error(exception); > + log.error(exception.getStackTrace()); > + > gErrors += 1; > if (gCalls + gErrors >= clients * loops) > printStats (); > Index: src/test/org/apache/xmlrpc/Benchmark.java > =================================================================== > RCS file: /home/cvspublic/xml-rpc/src/test/org/apache/xmlrpc/Benchmark.java,v > retrieving revision 1.2 > diff -u -r1.2 Benchmark.java > --- src/test/org/apache/xmlrpc/Benchmark.java 14 Nov 2001 15:12:01 -0000 1.2 > +++ src/test/org/apache/xmlrpc/Benchmark.java 9 Dec 2002 15:49:10 -0000 > @@ -58,6 +58,9 @@ > import java.util.*; > import java.io.IOException; > > +import org.apache.commons.logging.Log; > +import org.apache.commons.logging.LogFactory; > + > public class Benchmark > implements Runnable > { > @@ -95,6 +98,8 @@ > > public void run () > { > + Log log = LogFactory.getLog(Benchmark.class); > + > int errors = 0; > int calls = 0; > try > @@ -133,16 +138,17 @@ > } > catch (IOException x) > { > - System.err.println ("Exception in client: "+x); > - x.printStackTrace (); > + log.error("Exception in client: "+x); > + log.error(x.getStackTrace()); > } > catch (XmlRpcException x) > { > - System.err.println ("Server reported error: "+x); > + log.error("Server reported error: "+x); > + log.error(x.getStackTrace()); > } > catch (Exception other) > { > - System.err.println ("Exception in Benchmark client: "+other); > + log.error("Exception in Benchmark client: "+other); > } > int millis = (int)(System.currentTimeMillis () - start); > checkout (calls, errors, millis); -- Daniel Rall <[EMAIL PROTECTED]>