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