Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] kprintf with user formatters
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: james woodyatt <jhw@w...>
Subject: Re: [Caml-list] kprintf with user formatters
On 14 Jul 2004, at 17:17, Markus Mottl wrote:
> On Wed, 14 Jul 2004, Pierre Weis wrote:
>> Your problem is thus that the function Debug.printf is not the right
>> one (since it has not the right type :)
>
> Btw., since we are at it: I'd like to use my own printers depending on
> a conditional, e.g.:
>
>   let log level fmt =
>     if may_log level then
>       kfprintf ...
>     else
>       ???
>
> If the given log level "level" does not allow logging the message
> specified by "fmt", I just want to ignore the parameters provided 
> together
> with "fmt" - but how?  Is there some (safe) trick, or do I have to 
> write
> my own Printf/Format-modules?  I don't want to waste computation time
> by unnecessarily converting format arguments to strings, which may be
> very costly, e.g. when this would mean converting IPs to hostnames, 
> etc.

The next release of my [Cf] library (due probably sometime this 
weekend) contains the foundation of a flexible diagnostic event 
journaling system, which is inspired by Log4j and various other similar 
systems.

Using just the interface I'm almost ready to release now, the code 
would look like this:

	module J = Cf_journal

	if J.stdout#enabled `Info then
	  J.stdout#info "this is an informational message (x=%d) x

Note: because I plan to build this out to look a lot like Log4j, the 
format and its associated arguments are used to construct an event 
object and the event is sent to visit a list of archivers, each of 
which makes its own decision about how to write the events into their 
respective repositories.  The [#enabled] method can be used to 
short-cut the call to [kprintf] embedded in the journal agent's logging 
methods.  The example above is an example of using the built-in 
[stdout] basic agent, but that's a trivial example.

For debugging messages, I simply made the [#debug] method return [true] 
so that it will be easily used inside [assert] expressions, like so:

	assert (J.stdout#debug "this is a debug message (x=%d)" x)

I know this isn't what you want, but I don't see how there is a good 
way to get what you want.  I generally like the idea of using the 
-noassert compile time option to decide whether to include the code for 
generating console debugging logs.


-- 
j h woodyatt <jhw@wetware.com>
markets are only free to the people who own them.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners