public class Tracer extends Object
import static org.lsst.ccs.utilities.tracers.Tracer.* ;
....
public void myMethod(int arg) {
assert trace("myMethod called with" +arg) ;
// code
}
public void anotherMethod(String arg) {
assert stackTrace() ;
}
A developper can also use home-grown filters
import static org.lsst.ccs.utilities.tracers.Tracer.* ;
import org.lsst.ccs.mypackage.MyEnum ;
....
public void myMethod(int arg) {
assert trace(MyEnum.DOING_THIS, "myMethod called with" +arg) ;
// code
}
public void anotherMethod(String arg) {
assert stackTrace(MyEnum.DOING_THAT) ;
}
then if System property org.lsst.ccs.traces is set
the traces can be produced or not. Example of option
-Dorg.lsst.ccs.traces=DOING_THIS,DOING_THAT
By default the strings are printed to System.out but this can be changed.
If you want to delegate the reporting to another code (such as a Logger)
write a code implementing Tracer.Strategy
and deploy it using the ServiceLoader (or put the canonical
className as value for property org.lsst.ccs.traceReporter).
Other methods of this class are mostly to be used while debugging and do not
use keys for filtering.| Modifier and Type | Class and Description |
|---|---|
static class |
Tracer.MultiReporter
Convenience class to create a code that reports to many report "handlers".
|
static interface |
Tracer.Strategy
defines the behaviour of a tracer.
|
| Modifier and Type | Field and Description |
|---|---|
protected static String[] |
keys |
static Tracer.Strategy |
reporter |
| Constructor and Description |
|---|
Tracer() |
| Modifier and Type | Method and Description |
|---|---|
static Tracer.Strategy |
getReporter() |
static void |
setReporter(Tracer.Strategy reporter) |
static boolean |
stackTrace()
reports a complete stack trace of the current code execution.
|
protected static void |
stackTrace(int levelOut)
reports part a stacktrace starting at index levelOut
|
static boolean |
stackTrace(String filter)
reports a complete stack trace of the current code execution
only if the filter string is part of the org.lsst.ccs.traces
property.
|
static <T extends Enum> |
stackTrace(T enumElement)
reports a complete stack trace of the current code execution
only if the filter enum constant is cited in the org.lsst.ccs.traces
property.
|
static boolean |
trace(String traceString)
utility method to fire a trace.
|
static boolean |
trace(String filter,
String traceString)
reports a trace only if the filter string is part of the org.lsst.ccs.traces
property.
|
static <T extends Enum> |
trace(T enumElement,
String traceString)
uses an enum constant to filter the message passed to the tracer.
|
static boolean |
traceInfos(Object obj)
traces the package infos of a Class (including version).
|
static boolean |
traceOurMavenProperties(String projectName)
traces non-standard $Project.maven.properties.
|
static boolean |
tracePomProperties(String orgName,
String projectName)
traces standard pom properties as deployed by maven.
|
static boolean |
traceProperties(Object obj,
String propFile)
Trace properties linked to an object.
|
static boolean |
traceWhere(Object obj)
traces where a class comes from.
|
public static Tracer.Strategy reporter
protected static String[] keys
public static void setReporter(Tracer.Strategy reporter)
public static Tracer.Strategy getReporter()
public static boolean trace(String traceString)
traceString - will always be transmitted to code for reporting the tracepublic static boolean trace(String filter, String traceString)
filter - traceString - public static <T extends Enum> boolean trace(T enumElement, String traceString)
T - enumElement - traceString - public static boolean stackTrace()
public static boolean stackTrace(String filter)
filter - public static <T extends Enum> boolean stackTrace(T enumElement)
T - enumElement - protected static void stackTrace(int levelOut)
levelOut - public static boolean traceProperties(Object obj, String propFile)
obj - propFile - name of the property file (without leading slashpublic static boolean traceInfos(Object obj)
obj - can be an Object or a Classpublic static boolean traceWhere(Object obj)
obj - can be an Object or a Classpublic static boolean tracePomProperties(String orgName, String projectName)
orgName - name of organisation ("org.lsst")projectName - name of project ("org-lsst-ccs-core")public static boolean traceOurMavenProperties(String projectName)
projectName - name of project ("org-lsst-ccs-core")Copyright © 2013 LSST. All Rights Reserved.