Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-07-21 (08:59)
From: Jean-Christophe Filliatre <filliatr@l...>
Subject: Re: [Caml-list] Logging

Tiago Antão writes:
 > Are there any best practices/libraries regarding logging in CAML? My
 > main use for it will be debugging (I know there are debugging
 > facilities in CAML, but I am very used to using log as a debug tool -
 > think Log4J for instance)...

I'm also  using logging  as a  debug facility sometimes,  and I  use a
printf-like function for this purpose, as follows:

let log_ch = open_out "logfile"
let log = Format.formatter_of_out_channel log_ch
let () = at_exit (fun () -> Format.pp_print_flush log (); close_out log_ch)
let lprintf s = Format.fprintf log s

which provides a function lprintf of type

val lprintf : ('a, Format.formatter, unit) format -> 'a = <fun>

to be used like Format.printf.

This is surely not  the best way to do, and not  very powerful, but at
least  it is  convenient  to  use when  you  already have  Format-like
printers for your datatypes (using %a).

Hope this helps,