1open Printf 2open Xentoollog 3 4let stdio_vmessage min_level level errno ctx msg = 5 let level_str = level_to_string level 6 and errno_str = match errno with None -> "" | Some s -> sprintf ": errno=%d" s 7 and ctx_str = match ctx with None -> "" | Some s -> sprintf ": %s" s in 8 if compare min_level level <= 0 then begin 9 printf "%s%s%s: %s\n" level_str ctx_str errno_str msg; 10 flush stdout; 11 end 12 13let stdio_progress _ctx what percent dne total = 14 let nl = if dne = total then "\n" else "" in 15 printf "\rProgress %s %d%% (%Ld/%Ld)%s" what percent dne total nl; 16 flush stdout 17 18let create_stdio_logger ?(level=Info) () = 19 let cbs = { 20 vmessage = stdio_vmessage level; 21 progress = stdio_progress; } in 22 create "Xentoollog.stdio_logger" cbs 23 24let do_test level = 25 let lgr = create_stdio_logger ~level:level () in 26 begin 27 test lgr; 28 end 29 30let () = 31 let debug_level = ref Info in 32 let speclist = [ 33 ("-v", Arg.Unit (fun () -> debug_level := Debug), "Verbose"); 34 ("-q", Arg.Unit (fun () -> debug_level := Critical), "Quiet"); 35 ] in 36 let usage_msg = "usage: xtl [OPTIONS]" in 37 Arg.parse speclist (fun _ -> ()) usage_msg; 38 39 do_test !debug_level 40