| 1 package gnu.xquery.util; 2 import gnu.mapping.*; 3 import gnu.xml.XMLPrinter; 4 5 public class Debug 6 { 7 public static String tracePrefix = "XQuery-trace: "; 8 public static OutPort tracePort = null; 9 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 { 15 OutPort out = tracePort; 16 if (out == null) 17 { 18 try 19 { 20 out = new OutPort(new java.io.FileOutputStream (traceFilename, 21 traceShouldAppend)); 22 } 23 catch (Throwable 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 |