Mutex on logging

This commit is contained in:
Tony Garnock-Jones 2012-05-05 21:16:53 -04:00
parent 7d5a29c3d6
commit ca8ce5d180
1 changed files with 8 additions and 6 deletions

14
log.ml
View File

@ -18,13 +18,15 @@
open Lwt
open Sexp
let mtx = Lwt_mutex.create ()
let write_to_log label body =
try_lwt
lwt () = Lwt_io.print label in
lwt () = Lwt_io.print ": " in
lwt () = output_sexp_human Lwt_io.stdout body in
Lwt_io.printl ""
with _ -> return ()
Lwt_mutex.with_lock mtx (fun () ->
try_lwt
lwt () = Lwt_io.print label in
lwt () = Lwt_io.print ": " in
lwt () = output_sexp_human Lwt_io.stdout body in
Lwt_io.printl ""
with _ -> return ())
let hook = ref write_to_log