Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Dez 29 2005 18:38:29 CET
file stats: LOC: 302   Methods: 21
NCLOC: 107   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Trace.java 50% 39,5% 52,4% 44,3%
coverage coverage
 1    /* $Id: Trace.java,v 1.9 2005/08/11 20:37:22 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2005, 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.9 $
 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 out = stream;
 59    }
 60   
 61    /**
 62    * Trace object.
 63    *
 64    * @param tracingObject Instance that wants to make a trace entry.
 65    * @param method Method of that object.
 66    * @param object Object to trace.
 67    */
 68  16437 public static void trace(final Object tracingObject, final String method,
 69    final Object object) {
 70  16437 printObjectMethod(tracingObject, method);
 71  16437 out.println(object);
 72    }
 73   
 74    /**
 75    * Trace object.
 76    *
 77    * @param tracingClass Class that wants to make a trace entry.
 78    * @param method Method of that class.
 79    * @param object Object to trace.
 80    */
 81  846 public static void trace(final Class tracingClass, final String method,
 82    final Object object) {
 83  846 printClassMethod(tracingClass, method);
 84  846 out.println(object);
 85    }
 86   
 87    /**
 88    * Trace throwable.
 89    *
 90    * @param tracingObject Instance that wants to make a trace entry.
 91    * @param method Method of that object.
 92    * @param throwable Throwable to trace.
 93    */
 94  1 public static void trace(final Object tracingObject, final String method,
 95    final Throwable throwable) {
 96  1 printObjectMethod(tracingObject, method);
 97  1 out.println(throwable);
 98  1 throwable.printStackTrace(out);
 99    }
 100   
 101    /**
 102    * Trace throwable.
 103    *
 104    * @param tracingClass Class that wants to make a trace entry.
 105    * @param method Method of that class.
 106    * @param throwable Throwable to trace.
 107    */
 108  0 public static void trace(final Class tracingClass, final String method,
 109    final Throwable throwable) {
 110  0 printClassMethod(tracingClass, method);
 111  0 out.println(throwable);
 112  0 throwable.printStackTrace(out);
 113    }
 114   
 115    /**
 116    * Trace throwable and extra description.
 117    *
 118    * @param tracingObject Instance that wants to make a trace entry.
 119    * @param method Method of that object.
 120    * @param description Further information.
 121    * @param throwable Throwable to trace.
 122    */
 123  0 public static void trace(final Object tracingObject, final String method,
 124    final String description, final Throwable throwable) {
 125  0 printObjectMethod(tracingObject, method);
 126  0 out.println(description);
 127  0 printObjectMethod(tracingObject, method);
 128  0 out.println(throwable);
 129  0 throwable.printStackTrace(out);
 130    }
 131   
 132    /**
 133    * Trace throwable and extra description.
 134    *
 135    * @param tracingClass Class that wants to make a trace entry.
 136    * @param method Method of that class.
 137    * @param description Further information.
 138    * @param throwable Throwable to trace.
 139    */
 140  0 public static void trace(final Class tracingClass, final String method,
 141    final String description, final Throwable throwable) {
 142  0 printClassMethod(tracingClass, method);
 143  0 out.println(description);
 144  0 printClassMethod(tracingClass, method);
 145  0 out.println(throwable);
 146  0 throwable.printStackTrace(out);
 147    }
 148   
 149    /**
 150    * Trace method begin. Should be followed by an analogous
 151    * {@link #traceEnd(Object, String)} call.
 152    *
 153    * @param tracingObject Instance that wants to make a trace entry.
 154    * @param method Method of that object.
 155    */
 156  0 public static void traceBegin(final Object tracingObject, final String method) {
 157  0 trace(tracingObject, method, "begin");
 158    }
 159   
 160    /**
 161    * Trace method begin. Should be followed by an analogous {@link #traceEnd(Class, String)} call.
 162    *
 163    * @param tracingClass Class that wants to make a trace entry.
 164    * @param method Method of that class.
 165    */
 166  7 public static void traceBegin(final Class tracingClass, final String method) {
 167  7 trace(tracingClass, method, "begin");
 168    }
 169   
 170    /**
 171    * Trace method end.
 172    *
 173    * @param tracingObject Instance that wants to make a trace entry.
 174    * @param method Method of that object.
 175    */
 176  0 public static void traceEnd(final Object tracingObject, final String method) {
 177  0 trace(tracingObject, method, "end");
 178    }
 179   
 180    /**
 181    * Trace method end.
 182    *
 183    * @param tracingClass Class that wants to make a trace entry.
 184    * @param method Method of that class.
 185    */
 186  7 public static void traceEnd(final Class tracingClass, final String method) {
 187  7 trace(tracingClass, method, "end");
 188    }
 189   
 190    /**
 191    * Trace parameter.
 192    *
 193    * @param tracingObject Instance that wants to make a trace entry.
 194    * @param method Method of that object.
 195    * @param param Parameter to trace.
 196    * @param value Value of parameter.
 197    */
 198  15941 public static void traceParam(final Object tracingObject, final String method,
 199    final String param, final Object value) {
 200  15941 trace(tracingObject, method, param + "=" + value);
 201    }
 202   
 203    /**
 204    * Trace parameter.
 205    *
 206    * @param tracingClass Class that wants to make a trace entry.
 207    * @param method Method of that class.
 208    * @param param Parameter to trace.
 209    * @param value Value of parameter.
 210    */
 211  832 public static void traceParam(final Class tracingClass, final String method,
 212    final String param, final Object value) {
 213  832 trace(tracingClass, method, param + "=" + value);
 214    }
 215   
 216    /**
 217    * Trace parameter.
 218    *
 219    * @param tracingObject Instance that wants to make a trace entry.
 220    * @param method Method of that object.
 221    * @param param Parameter to trace.
 222    * @param value Value of parameter.
 223    */
 224  0 public static void traceParam(final Object tracingObject, final String method,
 225    final String param, final int value) {
 226  0 trace(tracingObject, method, param + "=" + value);
 227    }
 228   
 229    /**
 230    * Trace parameter.
 231    *
 232    * @param tracingClass Class that wants to make a trace entry.
 233    * @param method Method of that class.
 234    * @param param Parameter to trace.
 235    * @param value Value of parameter.
 236    */
 237  0 public static void traceParam(final Class tracingClass, final String method,
 238    final String param, final int value) {
 239  0 trace(tracingClass, method, param + "=" + value);
 240    }
 241   
 242    /**
 243    * Write stacktrace into trace.
 244    *
 245    * @param tracingObject Instance that wants to make a trace entry.
 246    * @param method Method of that object.
 247    */
 248  0 public static void traceStack(final Object tracingObject, final String method) {
 249  0 try {
 250  0 throw new Exception("Stacktrace");
 251    } catch (Exception e) {
 252  0 trace(tracingObject, method, e);
 253    }
 254    }
 255   
 256    /**
 257    * Write stacktrace into trace.
 258    *
 259    * @param tracingClass Class that wants to make a trace entry.
 260    * @param method Method of that class.
 261    */
 262  0 public static final void traceStack(final Class tracingClass, final String method) {
 263  0 try {
 264  0 throw new Exception("Stacktrace");
 265    } catch (Exception e) {
 266  0 trace(tracingClass, method, e);
 267    }
 268    }
 269   
 270    /**
 271    * Write traced location into trace.
 272    *
 273    * @param tracingObject Instance that wants to make a trace entry.
 274    * @param method Method of that class.
 275    */
 276  16438 private static final void printObjectMethod(final Object tracingObject, final String method) {
 277  16438 out.print(getTimestamp() + " [" + (tracingObject != null
 278    ? IoUtility.getClassName(tracingObject.getClass()) + "." : "")
 279    + method + "] ");
 280    }
 281   
 282    /**
 283    * Write traced location into trace.
 284    *
 285    * @param tracingClass Class that wants to make a trace entry.
 286    * @param method Method of that class.
 287    */
 288  846 private static final void printClassMethod(final Class tracingClass, final String method) {
 289  846 out.print(getTimestamp() + " [" + IoUtility.getClassName(tracingClass) + "."
 290    + method + "] ");
 291    }
 292   
 293    /**
 294    * Get current time.
 295    *
 296    * @return Current timestamp.
 297    */
 298  17284 private static final String getTimestamp() {
 299  17284 return FORMATTER.format(new Date()).toString();
 300    }
 301   
 302    }