The MessagePrinter
The MessagePrinter started off as a way to control output while doing unit tests, to control whether output went to stdout or to stderr, to generate output for unit tests that did not go into the log file. But it quickly became very useful as a way to have logging where using a logging package was inconvenient or created a "heavy linkage" in libraries that were intended to be light. At this point, its interface was overhauled to be a "work-alike" match for the Apache Commons Logging API. This allows a reference to an Apache Log object to be replaced with a MessagePrinter object instead--and all the code will still compile while severing the dependence on an external logging API or logging package.MessagePrinter is a concrete implementation of MessageLogger--an interface that is meant to duplicate the Apache Log interface. The MessagePrinter implemenation contains additional methods for printing banners, formatting objects, and returning the current code's location. For more information on the MessagePrinter and what it provides, see the API
.
Using MessagePrinter as a Apache Log substitue
The easiest way to use MessagePrinter for logging is to replace your class-level logger definition. Where normal logging package dependent code would have an declaration like:private static final Log logger = LoggingUtil.getLogger(YourClass.class);
You can just replace this definition with the following:
private static final MessageLogger logger = new MessagePrinter(true);
The new MessagePrinter(true); is the important part. The true value to the contructor tells the MessagePrinter instance to act like a logger. The result is that the MessagePrinter instance deduces its location using a StackTrace and then looks in the environment for "your.package.YourClass.level=something". It acts just like other logging packages, deferring to "parent" levels if no explicit level is found.
/rsh tech

