]> source.dussan.org Git - aspectj.git/commitdiff
Bug 150487 "Tracing and Logging Framework" (override TraceFactory, trace info, warn...
authormwebster <mwebster>
Mon, 14 Aug 2006 15:51:34 +0000 (15:51 +0000)
committermwebster <mwebster>
Mon, 14 Aug 2006 15:51:34 +0000 (15:51 +0000)
weaver/src/org/aspectj/weaver/tools/DefaultTrace.java
weaver/src/org/aspectj/weaver/tools/TraceFactory.java

index b50c081ec197fefe690a66dee4c65e6cc253caba..ddb03dbb5cca26e5dd7440d592ddfad7f44196c6 100644 (file)
@@ -56,38 +56,27 @@ public class DefaultTrace extends AbstractTrace {
                }
        }
        public void debug (String message) {
-               if (traceEnabled) {
-                       println(formatMessage("?",message,null));
-               }
+               println(formatMessage("?",message,null));
        }
 
        public void info(String message) {
-               if (traceEnabled) {
-                       println(formatMessage("I",message,null));
-               }
+               println(formatMessage("I",message,null));
        }
 
        public void warn (String message, Throwable th) {
-               if (traceEnabled) {
-                       println(formatMessage("W",message,th));
-                       if (th != null) th.printStackTrace();
-               }
+               println(formatMessage("W",message,th));
+               if (th != null) th.printStackTrace();
        }
 
 
        public void error (String message, Throwable th) {
-               if (traceEnabled) {
-                       println(formatMessage("E",message,th));
-                       if (th != null) th.printStackTrace();
-               }
-               
+               println(formatMessage("E",message,th));
+               if (th != null) th.printStackTrace();
        }
 
        public void fatal (String message, Throwable th) {
-               if (traceEnabled) {
-                       println(formatMessage("X",message,th));
-                       if (th != null) th.printStackTrace();
-               }
+               println(formatMessage("X",message,th));
+               if (th != null) th.printStackTrace();
        }
 
        /**
index beaaf862afb3334139a3121bbe29dd2d6afa42fe..dedceeadbc33a9a16897b60a10536baedd18d0a2 100644 (file)
@@ -16,9 +16,10 @@ public abstract class TraceFactory {
     
        public final static String DEBUG_PROPERTY = "org.aspectj.tracing.debug";
        public final static String FACTORY_PROPERTY = "org.aspectj.tracing.factory";
+       public final static String DEFAULT_FACTORY_NAME = "default";
        
     private static boolean debug = getBoolean(DEBUG_PROPERTY,false); 
-    private static TraceFactory instance = new DefaultTraceFactory();
+    private static TraceFactory instance;
     
     public Trace getTrace (Class clazz) {
        return instance.getTrace(clazz);
@@ -35,7 +36,28 @@ public abstract class TraceFactory {
        }
 
        static {
-       try {
+               
+               /*
+                * Allow user to override default behaviour or specify their own factory 
+                */
+               String factoryName = System.getProperty(FACTORY_PROPERTY);
+               if (factoryName != null) try {
+                       if (factoryName.equals(DEFAULT_FACTORY_NAME)) {
+                               instance = new DefaultTraceFactory();
+                       }
+                       else {
+                       Class factoryClass = Class.forName(factoryName);
+                       instance = (TraceFactory)factoryClass.newInstance();
+                       }
+               }
+       catch (Throwable th) {
+               if (debug) th.printStackTrace();
+       }
+       
+               /*
+                * Try to load external trace infrastructure using supplied factories
+                */
+       if (instance == null) try {
                        if (LangUtil.is15VMOrGreater()) {
                        Class factoryClass = Class.forName("org.aspectj.weaver.tools.Jdk14TraceFactory");
                        instance = (TraceFactory)factoryClass.newInstance();
@@ -47,6 +69,13 @@ public abstract class TraceFactory {
        catch (Throwable th) {
                if (debug) th.printStackTrace();
        }
+
+       /*
+                * Use default trace 
+                */
+       if (instance == null) {
+           instance = new DefaultTraceFactory();
+       }
        
        if (debug) System.out.println("TraceFactory.instance=" + instance);
     }