www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - new Trace addition for Tango, plus log.format()

reply "Kris" <foo bar.com> writes:
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 
Oct 02 2007
next sibling parent reply Mark Wrenn <mark-nospam binarytheory.com> writes:
Thanks for this.  Love the logging architecture BTW.  Nice work.

Kris wrote:
 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:
Oct 02 2007
parent "Kris" <foo bar.com> writes:
you're welcome!

- Kris

"Mark Wrenn" <mark-nospam binarytheory.com> wrote in message 
news:fdtu11$2aeh$1 digitalmars.com...
 Thanks for this.  Love the logging architecture BTW.  Nice work.

 Kris wrote:
 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: 
Oct 02 2007
prev sibling parent reply Robert Fraser <fraserofthenight gmail.com> writes:
Kris Wrote:

 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 
I never thought of using Chainsaw with Tango's logging! Any special configuration for that?
Oct 04 2007
parent "Kris" <foo bar.com> writes:
Well, you configure a Log4Layout with a SocketAppender ... similar to what 
Log4J does. There's an old example in the example/logging folder

- Kris


"Robert Fraser" <fraserofthenight gmail.com> wrote in message 
news:fe23h6$109k$1 digitalmars.com...
 Kris Wrote:

 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
I never thought of using Chainsaw with Tango's logging! Any special configuration for that?
Oct 04 2007