org.jcoderz.commons.tracing
Class JulTimingTracer

java.lang.Object
  extended by org.jcoderz.commons.tracing.JulTimingTracer
All Implemented Interfaces:
Tracer

public class JulTimingTracer
extends Object
implements Tracer

A Tracer implementation that used java.util.logging entering exiting logger as tracing sink and adds timing information. The format of the added timing information is '(after {0}ms)', the precision relies on System.currentTimeMillis(). See Logger.entering(String, String) for an example.

Author:
Andreas Mandel

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jcoderz.commons.tracing.Tracer
Tracer.TracingToken
 
Method Summary
 Tracer.TracingToken entering(String className, String methodName)
          Delegates to Logger.entering(String, String).
 Tracer.TracingToken entering(String className, String methodName, Object argument)
          Delegates to Logger.entering(String, String, Object).
 Tracer.TracingToken entering(String className, String methodName, Object[] arguments)
          Delegates to Logger.entering(String, String, Object).
 void exiting(Tracer.TracingToken token)
          Logs the method exit like Logger.exiting(String, String) with additional execution time information.
 void exiting(Tracer.TracingToken token, Object result)
          Logs the returned result like Logger.exiting(String, String, Object) with additional execution time information.
 String getClassName()
          Returns the Name of the class where this tracer belongs to.
static JulTimingTracer getTracer(String className)
          Factory for a tracer for classes with the given name.
 boolean isTracing()
          Returns true, if the level of the underlying java logger is Level.FINER or below.
 boolean isTracingArguments()
          Returns always true.
 void throwing(Tracer.TracingToken token, Throwable thrown)
          Logs the thrown exception like Logger.throwing(String, String, Throwable) with additional execution time information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTracer

public static JulTimingTracer getTracer(String className)
Factory for a tracer for classes with the given name.

Parameters:
className - the name of the class that uses this tracer.
Returns:
a tracer for the given class that dumps trace output to java logging.

isTracing

public boolean isTracing()
Returns true, if the level of the underlying java logger is Level.FINER or below.

Specified by:
isTracing in interface Tracer
See Also:
Tracer.isTracing()

isTracingArguments

public boolean isTracingArguments()
Returns always true.

Specified by:
isTracingArguments in interface Tracer
Returns:
true, if the tracer is evaluating the contents of the arguments.
See Also:
Tracer.isTracingArguments()

getClassName

public String getClassName()
Returns the Name of the class where this tracer belongs to.

Returns:
the Name of the class where this tracer belongs to.

entering

public Tracer.TracingToken entering(String className,
                                    String methodName)
Delegates to Logger.entering(String, String). The className is expected to be the same as the tracer name and is silently ignored.

Specified by:
entering in interface Tracer
Parameters:
className - name of the class
methodName - name of the method entered.
Returns:
a token, holding the context for the followup exiting / throwing call.
See Also:
Tracer.entering(java.lang.String, java.lang.String)

entering

public Tracer.TracingToken entering(String className,
                                    String methodName,
                                    Object argument)
Delegates to Logger.entering(String, String, Object). The className is expected to be the same as the tracer name and is silently ignored.

Specified by:
entering in interface Tracer
See Also:
Tracer.entering(String, String, Object)

entering

public Tracer.TracingToken entering(String className,
                                    String methodName,
                                    Object[] arguments)
Delegates to Logger.entering(String, String, Object). The className is expected to be the same as the tracer name and is silently ignored.

Specified by:
entering in interface Tracer
See Also:
Tracer.entering(String, String, Object[])

exiting

public void exiting(Tracer.TracingToken token)
Logs the method exit like Logger.exiting(String, String) with additional execution time information. If the token is not a JulTimingTracingToken the call is silently ignored.

Specified by:
exiting in interface Tracer
See Also:
Tracer.exiting(TracingToken)

exiting

public void exiting(Tracer.TracingToken token,
                    Object result)
Logs the returned result like Logger.exiting(String, String, Object) with additional execution time information. If the token is not a JulTimingTracingToken the call is silently ignored.

Specified by:
exiting in interface Tracer
See Also:
Tracer.exiting(TracingToken, java.lang.Object)

throwing

public void throwing(Tracer.TracingToken token,
                     Throwable thrown)
Logs the thrown exception like Logger.throwing(String, String, Throwable) with additional execution time information. If the token is not a JulTimingTracingToken the call is silently ignored.

Specified by:
throwing in interface Tracer
See Also:
Tracer.throwing(TracingToken, java.lang.Throwable)


Copyright 2007 The jCoderZ Project.