| |
| Posted by Kris | PermalinkReply |
|
Kris
| There's been some new developments here today. While Tango has always had a robust logging package reminiscent of Log4J, a lot of folk tend to use Stdout or Stderr instead. To better support the needs of simplistic debug tracing, a dedicated module has been added:
---------
import tango.util.log.Trace;
Trace.formatln ("temperature is {} degrees", 101);
---------
Note that this uses the same syntax (and code) as Stdout and friends, but is also synchronized/serialized (via an output filter, for those interested in such things). At some later point, it may optionally tie into the more capable logging package.
Speaking of which, the Tango logging package now internally supports formatted output:
-----------
import tango.util.log.Log;
void doingSomethingInteresting (Logger log)
{
char[128] tmp;
...
...
log.info (log.format (tmp, "temperature is {} degrees", celcius));
...
if (dangerous)
log.warn ("OMG! It's too freaking hot");
}
-----------
Two things to note:
1. log expressions are 'lazy', so they don't get evaluated unless the log instance is actually enabled for info, warnings, or the other categories.
2. the formatter requires a temporary buffer (the first argument) to construct the output within. This is so that (a) log formatting is thread-safe, and (b) the lazy expression can produce something within scope.
Log output-formatting is optional, of course, but it's handy when you need it. For those who are not familiar with Tango logging, it supports a variety of output styles, a selection of log 'targets' (console, network, files, email, etc) and is highly configurable both at compile time and runtime. Here's a simplistic example, where a console configuration shows milliseconds since the process started:
-----
2 Info example.logging - 167 prime numbers found in 2 millseconds
2 Trace example.logging - prime found: 1
2 Trace example.logging - prime found: 3
----
At runtime, for instance, you can hook an administrative web-page (package is provided) into your application to dynamically configure log-output at runtime. When combined with remote-logging to an network application such as Chainsaw, the combination enables dynamic & interactive monitoring of remote processes. This is often more useful than generic traces to the local console.
- Kris
|