|
Qualog is a Java library for inserting logging statements into code. It is a quasi logging module, meaning that it does not support many features from other logging modules, such as Log4J. It differs from Log4J in that it is nearly exclusively focused on output format, including color highlighting, stack traces, and collection unrolling. It requires a minimal amount of configuration, such that the following is sufficient: public static void main(String[] args)
{
tr.Ace.setVerbose(true);
tr.Ace.log("args", args);
}
This produces the following: [Example.java 89] {Example #main } args[0]: this
[ 89] { # } args[1]: is
[ 89] { # } args[2]: a
[ 89] { # } args[3]: test
The BasicsNamesThe Qualog code is in the package InitializationTo enable logging, simply call: tr.Ace.setVerbose(true); LoggingTo generate a simple logging statement: tr.Ace.log("I'm here");
This, by default, generates a line of output that includes the following,
based on where the To log a collection, including both C-style arrays, and objects of type
Collection comps = new HashSet();
comps.add("VIC-20");
comps.add("C64");
comps.add(new String[] { "][", "//e", "///" });
comps.add("XT");
tr.Ace.log("my computers", comps);
For C-style arrays: String[] langs = new String[] {
"C",
"C++",
"Java",
"Ruby"
};
tr.Ace.log("my languages", langs);
Collections are unrolled recursively. StacksInstead of one line of output, Qualog can write the stack from which the method was invoked: tr.Ace.stack("hello");
Output is: [Example.java 89] {Example #methodTwo } hello
[ 114] { #methodOne } ""
[ 34] { #<init> } ""
[Main.java 10] {Main #main } ""
Stacks can be generated for collections as well, with the full stack written only for the last object in the collection. Color HighlightingNormally, log output is written in plain text. On platforms that support it,
colors (and other text decorations) can be written instead, either by adding the
arguments to the tr.Ace.log(tr.Ace.BLUE, "skies ahead");
// equivalently:
tr.Ace.blue("iris");
tr.Ace.stack(tr.Ace.BOLD, "statement");
tr.Ace.stack(tr.Ace.REVERSE, "direction");
LevelsQualog supports logging levels, where the "coarsest" is simply verbose, or the equivalent being level 5, the default logging level where an explicit level is not used. However, logging can be done with more specific levels: tr.Ace.setOutput(tr.Ace.VERBOSE, tr.Ace.LEVEL8); tr.Ace.log(tr.Ace.LEVEL7, "this is logged"); tr.Ace.stack(tr.Ace.LEVEL9, "this is not logged"); ModesQualog supports two logging modes, verbose and quiet. The previous examples, with the "file:line ... class#method ... message" output format, show the result of verbose mode. In quiet mode, only the output message is displayed, not the file, line, class, or method. This supports output expected from using command-line options of "--verbose" versus "--quiet". Of course, levels (see the previous section) are applied to both modes, so the previous example would be: tr.Ace.setOutput(tr.Ace.QUIET, tr.Ace.LEVEL8); tr.Ace.log(tr.Ace.LEVEL7, "this message is displayed"); tr.Ace.stack(tr.Ace.LEVEL9, "but not this message"); FilteringQualog offers limited filtering, selectively applying colors to a given package, class, or method. In the following example, the class name of Range would be in red, and the class name of Pair would be displayed as bold: tr.Ace.setClassColor(Range.class.getName(), Qualog.RED); tr.Ace.setClassColor(Pair.class.getName(), Qualog.BOLD); OutputBy default, Qualog writes to standard error. This can be changed via the
tr.Ace.setOut(new PrintWriter(...)); ChainingThe if (x > 4 && tr.Ace.log("x: " + x) &&
y < 10 && tr.Ace.log("y: " + y) &&
z.contains("foo") && tr.Ace.log("foo is in z")) { ... }
This functionality makes it easy to insert debugging statements into the middle of conditionals, without interrupting the existing code. Example
See the API for more. |
|
