Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Okt 21 2006 08:24:31 CEST
file stats: LOC: 306   Methods: 21
NCLOC: 111   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Trace.java 50% 45% 61,9% 50,8%
coverage coverage
 1    /* $Id: Trace.java,v 1.10 2006/10/20 20:23:07 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2006, Michael Meyling <mime@qedeq.org>.
 6    *
 7    * "Hilbert II" is free software; you can redistribute
 8    * it and/or modify it under the terms of the GNU General Public
 9    * License as published by the Free Software Foundation; either
 10    * version 2 of the License, or (at your option) any later version.
 11    *
 12    * This program is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15    * GNU General Public License for more details.
 16    */
 17   
 18    package org.qedeq.kernel.log;
 19   
 20    import java.io.PrintStream;
 21    import java.text.SimpleDateFormat;
 22    import java.util.Date;
 23   
 24    import org.qedeq.kernel.utility.IoUtility;
 25   
 26   
 27    /**
 28    * Developer trace. If the trace output stream is not set via {@link #setPrintStream(PrintStream)}
 29    * the output goes to {@link java.lang.System#out}.
 30    *
 31    * @version $Revision: 1.10 $
 32    * @author Michael Meyling
 33    */
 34    public final class Trace {
 35   
 36    /** Write trace output to this stream. */
 37    private static PrintStream out = System.out;
 38   
 39    /** Date output format .*/
 40    private static final SimpleDateFormat FORMATTER
 41    = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss,SSS");
 42   
 43    // TODO mime 20050205: make output of qualified classname configurable
 44   
 45    /**
 46    * Constructor.
 47    */
 48  0 private Trace() {
 49    // don't call me
 50    }
 51   
 52    /**
 53    * Set trace output stream.
 54    *
 55    * @param stream New trace output.
 56    */
 57  3 public static void setPrintStream(final PrintStream stream) {
 58  3 if (stream != null) {
 59  3 out = stream;
 60    } else {
 61  0 out.println("Try to set trace output stream to null!");
 62    }
 63    }
 64   
 65    /**
 66    * Trace object.
 67    *
 68    * @param tracingObject Instance that wants to make a trace entry.
 69    * @param method Method of that object.
 70    * @param object Object to trace.
 71    */
 72  112550 public static void trace(final Object tracingObject, final String method,
 73    final Object object) {
 74  112550 printObjectMethod(tracingObject, method);
 75  112550 out.println(object);
 76    }
 77   
 78    /**
 79    * Trace object.
 80    *
 81    * @param tracingClass Class that wants to make a trace entry.
 82    * @param method Method of that class.
 83    * @param object Object to trace.
 84    */
 85  4915 public static void trace(final Class tracingClass, final String method,
 86    final Object object) {
 87  4915 printClassMethod(tracingClass, method);
 88  4915 out.println(object);
 89    }
 90   
 91    /**
 92    * Trace throwable.
 93    *
 94    * @param tracingObject Instance that wants to make a trace entry.
 95    * @param method Method of that object.
 96    * @param throwable Throwable to trace.
 97    */
 98  1 public static void trace(final Object tracingObject, final String method,
 99    final Throwable throwable) {
 100  1 printObjectMethod(tracingObject, method);
 101  1 out.println(throwable);
 102  1 throwable.printStackTrace(out);
 103    }
 104   
 105    /**
 106    * Trace throwable.
 107    *
 108    * @param tracingClass Class that wants to make a trace entry.
 109    * @param method Method of that class.
 110    * @param throwable Throwable to trace.
 111    */
 112  0 public static void trace(final Class tracingClass, final String method,
 113    final Throwable throwable) {
 114  0 printClassMethod(tracingClass, method);
 115  0 out.println(throwable);
 116  0 throwable.printStackTrace(out);
 117    }
 118   
 119    /**
 120    * Trace throwable and extra description.
 121    *
 122    * @param tracingObject Instance that wants to make a trace entry.
 123    * @param method Method of that object.
 124    * @param description Further information.
 125    * @param throwable Throwable to trace.
 126    */
 127  0 public static void trace(final Object tracingObject, final String method,
 128    final String description, final Throwable throwable) {
 129  0 printObjectMethod(tracingObject, method);
 130  0 out.println(description);
 131  0 printObjectMethod(tracingObject, method);
 132  0 out.println(throwable);
 133  0 throwable.printStackTrace(out);
 134    }
 135   
 136    /**
 137    * Trace throwable and extra description.
 138    *
 139    * @param tracingClass Class that wants to make a trace entry.
 140    * @param method Method of that class.
 141    * @param description Further information.
 142    * @param throwable Throwable to trace.
 143    */
 144  0 public static void trace(final Class tracingClass, final String method,
 145    final String description, final Throwable throwable) {
 146  0 printClassMethod(tracingClass, method);
 147  0 out.println(description);
 148  0 printClassMethod(tracingClass, method);
 149  0 out.println(throwable);
 150  0 throwable.printStackTrace(out);
 151    }
 152   
 153    /**
 154    * Trace method begin. Should be followed by an analogous
 155    * {@link #traceEnd(Object, String)} call.
 156    *
 157    * @param tracingObject Instance that wants to make a trace entry.
 158    * @param method Method of that object.
 159    */
 160  8348 public static void traceBegin(final Object tracingObject, final String method) {
 161  8348 trace(tracingObject, method, "begin");
 162    }
 163   
 164    /**
 165    * Trace method begin. Should be followed by an analogous {@link #traceEnd(Class, String)} call.
 166    *
 167    * @param tracingClass Class that wants to make a trace entry.
 168    * @param method Method of that class.
 169    */
 170  90 public static void traceBegin(final Class tracingClass, final String method) {
 171  90 trace(tracingClass, method, "begin");
 172    }
 173   
 174    /**
 175    * Trace method end.
 176    *
 177    * @param tracingObject Instance that wants to make a trace entry.
 178    * @param method Method of that object.
 179    */
 180  8348 public static void traceEnd(final Object tracingObject, final String method) {
 181  8348 trace(tracingObject, method, "end");
 182    }
 183   
 184    /**
 185    * Trace method end.
 186    *
 187    * @param tracingClass Class that wants to make a trace entry.
 188    * @param method Method of that class.
 189    */
 190  90 public static void traceEnd(final Class tracingClass, final String method) {
 191  90 trace(tracingClass, method, "end");
 192    }
 193   
 194    /**
 195    * Trace parameter.
 196    *
 197    * @param tracingObject Instance that wants to make a trace entry.
 198    * @param method Method of that object.
 199    * @param param Parameter to trace.
 200    * @param value Value of parameter.
 201    */
 202  86293 public static void traceParam(final Object tracingObject, final String method,
 203    final String param, final Object value) {
 204  86293 trace(tracingObject, method, param + "=" + value);
 205    }
 206   
 207    /**
 208    * Trace parameter.
 209    *
 210    * @param tracingClass Class that wants to make a trace entry.
 211    * @param method Method of that class.
 212    * @param param Parameter to trace.
 213    * @param value Value of parameter.
 214    */
 215  4735 public static void traceParam(final Class tracingClass, final String method,
 216    final String param, final Object value) {
 217  4735 trace(tracingClass, method, param + "=" + value);
 218    }
 219   
 220    /**
 221    * Trace parameter.
 222    *
 223    * @param tracingObject Instance that wants to make a trace entry.
 224    * @param method Method of that object.
 225    * @param param Parameter to trace.
 226    * @param value Value of parameter.
 227    */
 228  0 public static void traceParam(final Object tracingObject, final String method,
 229    final String param, final int value) {
 230  0 trace(tracingObject, method, param + "=" + value);
 231    }
 232   
 233    /**
 234    * Trace parameter.
 235    *
 236    * @param tracingClass Class that wants to make a trace entry.
 237    * @param method Method of that class.
 238    * @param param Parameter to trace.
 239    * @param value Value of parameter.
 240    */
 241  0 public static void traceParam(final Class tracingClass, final String method,
 242    final String param, final int value) {
 243  0 trace(tracingClass, method, param + "=" + value);
 244    }
 245   
 246    /**
 247    * Write stacktrace into trace.
 248    *
 249    * @param tracingObject Instance that wants to make a trace entry.
 250    * @param method Method of that object.
 251    */
 252  0 public static void traceStack(final Object tracingObject, final String method) {
 253  0 try {
 254  0 throw new Exception("Stacktrace");
 255    } catch (Exception e) {
 256  0 trace(tracingObject, method, e);
 257    }
 258    }
 259   
 260    /**
 261    * Write stacktrace into trace.
 262    *
 263    * @param tracingClass Class that wants to make a trace entry.
 264    * @param method Method of that class.
 265    */
 266  0 public static final void traceStack(final Class tracingClass, final String method) {
 267  0 try {
 268  0 throw new Exception("Stacktrace");
 269    } catch (Exception e) {
 270  0 trace(tracingClass, method, e);
 271    }
 272    }
 273   
 274    /**
 275    * Write traced location into trace.
 276    *
 277    * @param tracingObject Instance that wants to make a trace entry.
 278    * @param method Method of that class.
 279    */
 280  112551 private static final void printObjectMethod(final Object tracingObject, final String method) {
 281  112551 out.print(getTimestamp() + " [" + (tracingObject != null
 282    ? IoUtility.getClassName(tracingObject.getClass()) + "." : "")
 283    + method + "] ");
 284    }
 285   
 286    /**
 287    * Write traced location into trace.
 288    *
 289    * @param tracingClass Class that wants to make a trace entry.
 290    * @param method Method of that class.
 291    */
 292  4915 private static final void printClassMethod(final Class tracingClass, final String method) {
 293  4915 out.print(getTimestamp() + " [" + IoUtility.getClassName(tracingClass) + "."
 294    + method + "] ");
 295    }
 296   
 297    /**
 298    * Get current time.
 299    *
 300    * @return Current timestamp.
 301    */
 302  117466 private static final String getTimestamp() {
 303  117466 return FORMATTER.format(new Date());
 304    }
 305   
 306    }