jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r713882 - in /jackrabbit/sandbox/jcrlog: pom.xml src/main/java/org/apache/jackrabbit/jcrlog/Log.java src/main/java/org/apache/jackrabbit/jcrlog/LogObject.java src/main/java/org/apache/jackrabbit/jcrlog/RepositoryLogger.java
Date Fri, 14 Nov 2008 00:25:59 GMT
Author: tripod
Date: Thu Nov 13 16:25:58 2008
New Revision: 713882

URL: http://svn.apache.org/viewvc?rev=713882&view=rev
Log:
Improving / Fixing JCR Logger

Modified:
    jackrabbit/sandbox/jcrlog/pom.xml
    jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/Log.java
    jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/LogObject.java
    jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/RepositoryLogger.java

Modified: jackrabbit/sandbox/jcrlog/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcrlog/pom.xml?rev=713882&r1=713881&r2=713882&view=diff
==============================================================================
--- jackrabbit/sandbox/jcrlog/pom.xml (original)
+++ jackrabbit/sandbox/jcrlog/pom.xml Thu Nov 13 16:25:58 2008
@@ -19,48 +19,45 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                              http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  <prerequisites>
-    <maven>2.0.4</maven>
-  </prerequisites>
-  <groupId>org.apache.jackrabbit</groupId>
-  <parent>
+    <modelVersion>4.0.0</modelVersion>
+    <prerequisites>
+        <maven>2.0.4</maven>
+    </prerequisites>
     <groupId>org.apache.jackrabbit</groupId>
-    <artifactId>jackrabbit</artifactId>
+    <parent>
+        <groupId>org.apache.jackrabbit</groupId>
+        <artifactId>jackrabbit</artifactId>
+        <version>1.4</version>
+        <relativePath>../..</relativePath>
+    </parent>
+    <artifactId>jackrabbit-jcrlog</artifactId>
     <version>1.4-SNAPSHOT</version>
-    <relativePath>../..</relativePath>
-  </parent>
-  <artifactId>jackrabbit-jcrlog</artifactId>
-  <version>1.4-SNAPSHOT</version>
-  <packaging>jar</packaging>
-  <name>JCR log</name>
-  <description>JCR log/trace wrapper</description>
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.jackrabbit</groupId>
-      <artifactId>jackrabbit-core</artifactId>
-      <version>1.4-SNAPSHOT</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-      <groupId>javax.jcr</groupId>
-      <artifactId>jcr</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>3.8.1</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-      <version>1.3.0</version>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-log4j12</artifactId>
-      <version>1.3.0</version>
-    </dependency>
-  </dependencies>
-</project>
\ No newline at end of file
+    <packaging>jar</packaging>
+    <name>JCR log</name>
+    <description>JCR log/trace wrapper</description>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-core</artifactId>
+            <version>1.4.6</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-api</artifactId>
+            <version>1.4</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

Modified: jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/Log.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/Log.java?rev=713882&r1=713881&r2=713882&view=diff
==============================================================================
--- jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/Log.java (original)
+++ jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/Log.java Thu Nov
13 16:25:58 2008
@@ -50,6 +50,7 @@
     private boolean logCaller = true;
     private boolean castToRealApi = false;
     private boolean logStream = false;
+    private boolean logException = false;
 
     private static void createDirs(String fileName) throws IOException {
         File f = new File(fileName);
@@ -193,4 +194,11 @@
         return logStream;
     }
 
+    boolean getLogException() {
+        return logException;
+    }
+
+    void setLogException(boolean logException) {
+        this.logException = logException;
+    }
 }

Modified: jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/LogObject.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/LogObject.java?rev=713882&r1=713881&r2=713882&view=diff
==============================================================================
--- jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/LogObject.java (original)
+++ jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/LogObject.java Thu
Nov 13 16:25:58 2008
@@ -171,18 +171,18 @@
         logReturn();
         if (t instanceof RepositoryException) {
             RepositoryException r = (RepositoryException) t;
-            logException("RepositoryException", r);
+            logException("RepositoryException", r, true);
             return r;
         } else if (t instanceof RuntimeException) {
             RuntimeException r = (RuntimeException) t;
-            logException("RuntimeException", r);
+            logException("RuntimeException", r, true);
             throw r;
         } else if (t instanceof Error) {
             Error r = (Error) t;
-            logException("Error", r);
+            logException("Error", r, true);
             throw r;
         } else {
-            logException("Internal", t);
+            logException("Internal", t, true);
             throw new Error("Internal exception: " + t.toString());
         }
     }
@@ -191,14 +191,14 @@
         logReturn();
         if (t instanceof RuntimeException) {
             RuntimeException r = (RuntimeException) t;
-            logException("RuntimeException", r);
+            logException("RuntimeException", r, true);
             return r;
         } else if (t instanceof Error) {
             Error r = (Error) t;
-            logException("Error", r);
+            logException("Error", r, true);
             throw r;
         } else {
-            logException("LoggerException", t);
+            logException("LoggerException", t, true);
             throw new Error("Internal exception: " + t.toString());
         }
     }
@@ -285,16 +285,21 @@
         }
     }
 
-    private void logException(String title, Throwable e) {
-        log.write("//" + title + ": " + e.toString(), e);
+    private void logException(String title, Throwable e, boolean trace) {
+        log.write("//" + title + ": " + e.toString(), trace ? e : null);
     }
 
     protected void logReturn(Class clazz, Object result) {
         logReturn();
-        if (clazz == String.class && StringUtils.isUUID((String)result)) {
-            log.write("//return " + StringUtils.quote(clazz, result) + "; // UUID", null);
-        } else if (log.getLogReturn()) {
-            log.write("//return " + StringUtils.quote(clazz, result) + ";", null);
+        if (log.getLogReturn()) {
+            if (clazz == String.class
+                    && result != null
+                    && !result.getClass().isArray()
+                    && StringUtils.isUUID((String)result)) {
+                log.write("//return " + StringUtils.quote(clazz, result) + "; // UUID", null);
+            } else {
+                log.write("//return " + StringUtils.quote(clazz, result) + ";", null);
+            }
         }
     }
 
@@ -331,8 +336,16 @@
 
         Class proxyClass = idef.proxyClass;
         if (proxyClass == null) {
-            proxyClass = Proxy.getProxyClass(clazz.getClassLoader(),
-                    new Class[] { clazz });
+            // hack for node/property
+            Class[] interfaces;
+            if (clazz == Item.class && obj instanceof Node) {
+                interfaces = new Class[]{clazz, Node.class};
+            } else if (clazz == Item.class && obj instanceof Property) {
+                interfaces = new Class[]{clazz, Property.class};
+            } else {
+                interfaces = new Class[]{clazz};
+            }
+            proxyClass = Proxy.getProxyClass(clazz.getClassLoader(), interfaces);
             idef.proxyClass = proxyClass;
         }
         try {
@@ -341,7 +354,7 @@
                     new Object[] { handler });
             return o2;
         } catch (Exception e) {
-            logException("InvocationTargetException", e);
+            logException("InvocationTargetException", e, true);
             throw new Error("Internal exception: " + e.toString());
         }
     }
@@ -370,6 +383,14 @@
             wrapStreams(method.getParameterTypes(), args);
             int nextId = logStart(returnType, array, method.getName(),
                     StringUtils.quoteArgs(method.getParameterTypes(), args));
+            // unwrap args
+            if (args != null) {
+                for (int i=0; i<args.length; i++) {
+                    if (args[i] instanceof Proxy) {
+                        args[i] = ((LogObject) Proxy.getInvocationHandler(args[i])).getObject();
+                    }
+                }
+            }
             result = method.invoke(obj, args);
             if (log.getCastToRealApi() && result != null && idef != null)
{
                 InterfaceDef idef2 = LogObject.getInterface(result.getClass());
@@ -383,19 +404,22 @@
                     returnClass = idef2.interfaceClass;
                 }
             }
-            if (returnType >= 0) {
+            if (returnType >= 0 && result != null) {
                 result = wrap(result, array, returnClass, returnType, nextId);
             }
             logReturn(returnClass, result);
             return result;
         } catch (IllegalArgumentException e) {
-            logException("IllegalArgumentException", e);
+            logException("IllegalArgumentException", e, true);
             throw new Error("Internal exception: " + e.toString());
         } catch (IllegalAccessException e) {
-            logException("IllegalAccessException", e);
+            logException("IllegalAccessException", e, true);
             throw new Error("Internal exception: " + e.toString());
         } catch (InvocationTargetException e) {
             Throwable t = e.getTargetException();
+            if (log.getLogException()) {
+                logException("TargetException", t, false);
+            }
             throw t;
         }
     }

Modified: jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/RepositoryLogger.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/RepositoryLogger.java?rev=713882&r1=713881&r2=713882&view=diff
==============================================================================
--- jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/RepositoryLogger.java
(original)
+++ jackrabbit/sandbox/jcrlog/src/main/java/org/apache/jackrabbit/jcrlog/RepositoryLogger.java
Thu Nov 13 16:25:58 2008
@@ -85,7 +85,7 @@
         return new RepositoryLogger(repository, prop, url);
     }
 
-    private RepositoryLogger(Repository repository, Properties prop, String url)
+    public RepositoryLogger(Repository repository, Properties prop, String url)
             throws RepositoryException {
         this.repository = repository;
         String fileName = prop.getProperty("file");
@@ -94,11 +94,13 @@
         String logCaller = prop.getProperty("caller");
         String cast = prop.getProperty("cast");
         String stream = prop.getProperty("stream");
+        String exception = prop.getProperty("exception");
         Log log = new Log(fileName, parseBoolean(sysOut));
         log.setLogCaller(parseBoolean(logCaller));
         log.setLogReturn(parseBoolean(logReturn));
         log.setCastToRealApi(parseBoolean(cast));
         log.setLogStream(parseBoolean(stream));
+        log.setLogException(parseBoolean(exception));
         String call = RepositoryFactory.CLASSNAME + ".open("
                 + StringUtils.quoteString(url) + ");";
         int nextId = getNextId(LogObject.INTERFACE_DEF_REPOSITORY.type);



Mime
View raw message