|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.developersupport.Debug
Collection of miscellaneous utility methods that may occasionally aid debugging.
Method Summary | |
static void |
dumpToFile(String filename,
char[] chars)
Dump a character array to the file. |
static void |
dumpToFile(String filename,
String text)
Useful if you want to examine the string text in an
editor. |
static Object |
getPrivateField(Class klass,
Object obj,
String fieldName)
This method allows you to access a private field named fieldName of the object obj . |
static String |
readFile(String filename)
|
static String |
setLevel(String loggerName,
String level)
Manipulates the logging level for the specified logger. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void dumpToFile(String filename, String text)
text
in an
editor. Typical use pattern:
Debug.dumpToFile("/tmp/suspect-string.txt", suspectString);
Possible IO exceptions will be logged but not rethrown.
public static void dumpToFile(String filename, char[] chars)
dumpToFile(String, String)
public static String readFile(String filename)
public static Object getPrivateField(Class klass, Object obj, String fieldName) throws SecurityException
fieldName
of the object obj
.
Example usage:
public void doStuff(Foo foo) { Baz baz = (Baz) Debug.getPrivateField(Foo.class, foo, "m_baz"); System.err.println("foo's private field m_baz is " + baz); // do stuff with foo // ... }
klass
- the class of obj
obj
- the object whose field is being accessedfieldName
- the name of the field being accessed
SecurityException
- if there is a security
manager
and its SecurityManager.checkPermission(java.security.Permission)
method returns
true
for the
ReflectPermission("suppressAccessChecks")
permission. Note
that this is an unchecked exception.AccessibleObject.setAccessible(boolean)
,
ReflectPermission
public static String setLevel(String loggerName, String level)
Possible use case: Suppose you want to log db queries generated as a
result of executing the method foo()
. One way to do this is
to set the level for the
"com.redhat.persistence.engine.rdbms"
logger to
"info"
in enterprise.init
. However, this will
result in all queries being logged, producing a flood of
debugging information that you have to wade through to find queries that
are of interest to you.
An alternative is to do something like this:
String old = Debug.setLevel("com.redhat.persistence.engine.rdbms", "info"); foo(); Debug.setLevel("com.redhat.persistence.engine.rdbms", old); // or Debug.setLevel("com.redhat.persistence.engine.rdbms", "off");
Note, however, that although this method allows you to eliminate a
lot of unnecessary clutter, it fails to eliminate all of it. In the
presence of multiple threads of execution, methods other than
foo()
may execute within the same time slice. These other
methods executing concurrently may produce additional logging in the
com.redhat.persistence.engine
package.
loggerName
- the name of the logger, usually the name of a classlevel
- the logger level; one of "debug"
,
"info"
, "warn"
, "error"
,
"fatal"
, or "off"
. If an invalid level name is
passed, the level will default to "debug"
.
Level
,
Logger
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |