The only pure Java Subversion library in the world!
Home Get Library Knowledge Base Licensing

Setting a custom logger (for debug logging)

When you're using JavaSVN in your application it is not always an option to let JavaSVN use JDK logging API. Instead you may like to have a fine-grained control over the way JavaSVN logs its operations. The solution is to provide JavaSVN with a custom logger class that should extend the SVNDebugLoggerAdapter class. The code below demonstrates how it could be done.

...
import org.tmatesoft.svn.util.SVNDebugLog;
import org.tmatesoft.svn.util.SVNDebugLoggerAdapter;
...
    
    /*
     * Set up your logger
     */
    public static void initJavaSVNLogger() {
        SVNDebugLog.setLogger(new CustomJavaSVNLogger());
    }

    private static class CustomJavaSVNLogger 
                                   extends SVNDebugLoggerAdapter {
    	/* Override superclass methods to redirect logging
    	 * as you wish. Superclass implementaion is empty, i.e.
    	 * all log messages are swallowed.
    	 */
         
         
         public void log(String message, byte[] data) {
             /*
              * Used to log all data received or transmitted 
              * over network
              */
             ...
         }
         
         public void logInfo(String message) {
             /*
              * Used to log information messages
              */
             ...
         }

         public void logError(String message) {
             /*
              * Used to log error messages
              */
             ... 
         }

         public void logInfo(Throwable th) {
             /*
              * Used to log information on exceptions
              */
             ...
         }

         public void logError(Throwable th) {
             /*
              * Used to log exceptions
              */
             ...
         }
    }
...
    initJavaSVNLogger();
...    

Note: One have to set up a custom logger before any other calls are made to JavaSVN, otherwise default logging will be used - i.e. DefaultSVNDebugLogger (org.tmatesoft.svn.core.internal.util). How to obtain its log files read this article.



If you have any questions regarding JavaSVN, would like to report a bug or contribute a patch, please write to support@tmatesoft.com