[log] add option to print all logs to the console

Summary:
For example: `infer --print-logs --stats -- clang -c hello.c`.

The option is not on by default.

This forwards all the output to log files to stdout or stderr as appropriate.
The multiplexing is very crude and can be improved later if needed if
stdout/err is too garbled by concurrent partial writes.

Reviewed By: jberdine

Differential Revision: D4365996

fbshipit-source-id: 7f2ab98
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent f3190bc1f0
commit d01d0b81e9

@ -991,6 +991,10 @@ and precondition_stats =
CLOpt.mk_bool ~deprecated:["precondition_stats"] ~long:"precondition-stats"
"Print stats about preconditions to standard output"
and print_logs =
CLOpt.mk_bool ~long:"print-logs" ~exes:CLOpt.[Toplevel]
"Also log messages to stdout and stderr"
and print_builtins =
CLOpt.mk_bool ~deprecated:["print_builtins"] ~long:"print-builtins"
"Print the builtin functions and exit"
@ -1483,6 +1487,7 @@ and patterns_skip_translation = match patterns_skip_translation with (k,r) -> (k
and patterns_modeled_expensive = match patterns_modeled_expensive with (k,r) -> (k,!r)
and pmd_xml = !pmd_xml
and precondition_stats = !precondition_stats
and print_logs = !print_logs
and print_builtins = !print_builtins
and print_traces_in_tests = !print_traces_in_tests
and print_types = !print_types

@ -228,6 +228,7 @@ val only_footprint : bool
val out_file_cmdline : string
val pmd_xml : bool
val precondition_stats : bool
val print_logs : bool
val print_builtins : bool
val print_traces_in_tests : bool
val print_types : bool

@ -17,6 +17,17 @@ module CLOpt = CommandLineOption
(* log files *)
let dup_formatter fmt1 fmt2 =
let (out_string1, flush1) =
Format.pp_get_formatter_output_functions fmt1 () in
let (out_string2, flush2) =
Format.pp_get_formatter_output_functions fmt2 () in
(* crude multiplexing; may cause garbled output if a formatter is shared between several
processes *)
let out_string s p n = out_string1 s p n; out_string2 s p n in
let flush () = flush1 (); flush2 () in
Format.pp_set_formatter_output_functions fmt1 out_string flush
(** Name of dir for logging the output in the specific executable *)
let log_dir_of_exe (exe : CLOpt.exe) =
match exe with
@ -60,6 +71,12 @@ let create_log_file exe name_prefix outerr =
F.fprintf file_fmt
"---- start logging from %d -------------------------------------------@."
(Pid.to_int (Unix.getpid ()));
if Config.print_logs then (
let outerr_fmt = match outerr with
| `Out -> Format.std_formatter
| `Err -> Format.err_formatter in
dup_formatter file_fmt outerr_fmt
);
(* flush files on exit *)
Pervasives.at_exit (fun () -> close_log_file (lazy file_fmt) (lazy chan) (lazy file));
(file_fmt, chan, file)

Loading…
Cancel
Save