From 6bf6295895351381b81fdf1cb625ea8e81032c1a Mon Sep 17 00:00:00 2001 From: mwebster Date: Mon, 14 Aug 2006 15:51:34 +0000 Subject: [PATCH] Bug 150487 "Tracing and Logging Framework" (override TraceFactory, trace info, warn, error, fatal by default) --- .../aspectj/weaver/tools/DefaultTrace.java | 27 +++++---------- .../aspectj/weaver/tools/TraceFactory.java | 33 +++++++++++++++++-- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/tools/DefaultTrace.java b/weaver/src/org/aspectj/weaver/tools/DefaultTrace.java index b50c081ec..ddb03dbb5 100644 --- a/weaver/src/org/aspectj/weaver/tools/DefaultTrace.java +++ b/weaver/src/org/aspectj/weaver/tools/DefaultTrace.java @@ -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(); } /** diff --git a/weaver/src/org/aspectj/weaver/tools/TraceFactory.java b/weaver/src/org/aspectj/weaver/tools/TraceFactory.java index beaaf862a..dedceeadb 100644 --- a/weaver/src/org/aspectj/weaver/tools/TraceFactory.java +++ b/weaver/src/org/aspectj/weaver/tools/TraceFactory.java @@ -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); } -- 2.39.5