01: package gnu.xquery.util;
02:
03: import gnu.mapping.*;
04: import gnu.xml.XMLPrinter;
05:
06: public class Debug {
07: public static String tracePrefix = "XQuery-trace: ";
08: public static OutPort tracePort = null;
09: public static String traceFilename = "XQuery-trace.log";
10: public static boolean traceShouldFlush = true;
11: public static boolean traceShouldAppend = false;
12:
13: public static synchronized Object trace(Object value, Object message) {
14: OutPort out = tracePort;
15: if (out == null) {
16: try {
17: out = new OutPort(new java.io.FileOutputStream(
18: traceFilename, traceShouldAppend));
19: } catch (Throwable ex) {
20: new WrappedException("Could not open '" + traceFilename
21: + "' for fn:trace output", ex);
22: }
23: tracePort = out;
24: }
25: out.print(tracePrefix);
26: out.print(message);
27: out.print(' ');
28: XMLPrinter xout = new XMLPrinter(out, false);
29: xout.writeObject(value);
30: out.println();
31: if (traceShouldFlush)
32: out.flush();
33: return value;
34: }
35: }
|