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 SVNKit in your application it is not always an option to let SVNKit use JDK logging API. Instead you may like to have a fine-grained control over the way SVNKit logs its operations. The solution is to provide SVNKit 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 initSVNKitLogger() {
        SVNDebugLog.setLogger(new CustomSVNKitLogger());
    }

    private static class CustomSVNKitLogger 
                                   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
              */
             ...
         }
    }
...
    initSVNKitLogger();
...    

Note: One have to set up a custom logger before any other calls are made to SVNKit, 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 SVNKit, would like to report a bug or contribute a patch, please write to support@svnkit.com


Java™ and all Java-based marks are a trademark or registered trademark of Sun Microsystems, Inc, in the United States and other countries. TMate Software and the website svnkit.com are independent of Sun Microsystems, Inc. and have no relationship, formal or informal.