KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > xquery > util > Debug


1 package gnu.xquery.util;
2 import gnu.mapping.*;
3 import gnu.xml.XMLPrinter;
4
5 public class Debug
6 {
7   public static String JavaDoc tracePrefix = "XQuery-trace: ";
8   public static OutPort tracePort = null;
9   public static String JavaDoc traceFilename = "XQuery-trace.log";
10   public static boolean traceShouldFlush = true;
11   public static boolean traceShouldAppend = false;
12
13   public static synchronized Object JavaDoc trace (Object JavaDoc value, Object JavaDoc message)
14   {
15     OutPort out = tracePort;
16     if (out == null)
17       {
18         try
19           {
20             out = new OutPort(new java.io.FileOutputStream JavaDoc(traceFilename,
21                                                            traceShouldAppend));
22           }
23         catch (Throwable JavaDoc ex)
24           {
25             new WrappedException("Could not open '"+traceFilename
26                                  +"' for fn:trace output", ex);
27           }
28         tracePort = out;
29       }
30     out.print(tracePrefix);
31     out.print(message);
32     out.print(' ');
33     XMLPrinter xout = new XMLPrinter(out, false);
34     xout.writeObject(value);
35     out.println();
36     if (traceShouldFlush)
37       out.flush();
38     return value;
39   }
40 }
41
Popular Tags