summaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoraclement <aclement>2006-11-22 10:24:38 +0000
committeraclement <aclement>2006-11-22 10:24:38 +0000
commitf09bf4ff471e3d8a407d5c062a5e5c1c205e66db (patch)
treead3ec09102c08db7b727a624a0747e68f515395f /weaver
parentbb14e258c5d1769b3987a2e11f02c29f90f30e36 (diff)
downloadaspectj-f09bf4ff471e3d8a407d5c062a5e5c1c205e66db.tar.gz
aspectj-f09bf4ff471e3d8a407d5c062a5e5c1c205e66db.zip
tests and implementation for 165153: outputting aspectj trace to a named file
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/tools/DefaultTrace.java12
-rw-r--r--weaver/src/org/aspectj/weaver/tools/DefaultTraceFactory.java21
-rw-r--r--weaver/src/org/aspectj/weaver/tools/TraceFactory.java2
-rw-r--r--weaver/testsrc/org/aspectj/weaver/DefaultTraceTest.java5
4 files changed, 37 insertions, 3 deletions
diff --git a/weaver/src/org/aspectj/weaver/tools/DefaultTrace.java b/weaver/src/org/aspectj/weaver/tools/DefaultTrace.java
index 788bc95eb..ad95bbb3e 100644
--- a/weaver/src/org/aspectj/weaver/tools/DefaultTrace.java
+++ b/weaver/src/org/aspectj/weaver/tools/DefaultTrace.java
@@ -10,9 +10,13 @@
*******************************************************************************/
package org.aspectj.weaver.tools;
+import java.io.PrintStream;
+
+
public class DefaultTrace extends AbstractTrace {
- private boolean traceEnabled = false;
+ private boolean traceEnabled = false;
+ private PrintStream print = System.err;
public DefaultTrace (Class clazz) {
super(clazz);
@@ -98,7 +102,11 @@ public class DefaultTrace extends AbstractTrace {
* @param s message to be traced
*/
protected void println (String s) {
- System.err.println(s);
+ print.println(s);
+ }
+
+ public void setPrintStream (PrintStream printStream) {
+ this.print = printStream;
}
// private static boolean isTracingEnabled = getBoolean("org.aspectj.weaver.tools.tracing",false);
diff --git a/weaver/src/org/aspectj/weaver/tools/DefaultTraceFactory.java b/weaver/src/org/aspectj/weaver/tools/DefaultTraceFactory.java
index 66a63484c..c7860589a 100644
--- a/weaver/src/org/aspectj/weaver/tools/DefaultTraceFactory.java
+++ b/weaver/src/org/aspectj/weaver/tools/DefaultTraceFactory.java
@@ -10,12 +10,32 @@
*******************************************************************************/
package org.aspectj.weaver.tools;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
public class DefaultTraceFactory extends TraceFactory {
public final static String ENABLED_PROPERTY = "org.aspectj.tracing.enabled";
+ public final static String FILE_PROPERTY = "org.aspectj.tracing.file";
private boolean tracingEnabled = getBoolean(ENABLED_PROPERTY,false);
+ private PrintStream print;
+ public DefaultTraceFactory() {
+ String filename = System.getProperty(FILE_PROPERTY);
+ if (filename != null) {
+ File file = new File(filename);
+ try {
+ print = new PrintStream(new FileOutputStream(file));
+ }
+ catch (IOException ex) {
+ if (debug) ex.printStackTrace();
+ }
+ }
+ }
+
public boolean isEnabled() {
return tracingEnabled;
}
@@ -23,6 +43,7 @@ public class DefaultTraceFactory extends TraceFactory {
public Trace getTrace (Class clazz) {
DefaultTrace trace = new DefaultTrace(clazz);
trace.setTraceEnabled(tracingEnabled);
+ if (print != null) trace.setPrintStream(print);
return trace;
}
diff --git a/weaver/src/org/aspectj/weaver/tools/TraceFactory.java b/weaver/src/org/aspectj/weaver/tools/TraceFactory.java
index 41c6b9f57..6d819de50 100644
--- a/weaver/src/org/aspectj/weaver/tools/TraceFactory.java
+++ b/weaver/src/org/aspectj/weaver/tools/TraceFactory.java
@@ -18,7 +18,7 @@ public abstract class TraceFactory {
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);
+ protected static boolean debug = getBoolean(DEBUG_PROPERTY,false);
private static TraceFactory instance;
public Trace getTrace (Class clazz) {
diff --git a/weaver/testsrc/org/aspectj/weaver/DefaultTraceTest.java b/weaver/testsrc/org/aspectj/weaver/DefaultTraceTest.java
index b582d9bc4..fef476c49 100644
--- a/weaver/testsrc/org/aspectj/weaver/DefaultTraceTest.java
+++ b/weaver/testsrc/org/aspectj/weaver/DefaultTraceTest.java
@@ -29,4 +29,9 @@ public class DefaultTraceTest extends AbstractTraceTest {
trace.setTraceEnabled(true);
assertTrue(trace.isTraceEnabled());
}
+
+ public void testSetPrintStream () {
+ DefaultTrace trace = new DefaultTrace(getClass());
+ trace.setPrintStream(System.out);
+ }
}