diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index dd44a2b35..9cb835332 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -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 diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index aca39f71f..a81f6dd59 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -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 diff --git a/infer/src/base/Logging.ml b/infer/src/base/Logging.ml index 3eea990c3..88ee5cfa3 100644 --- a/infer/src/base/Logging.ml +++ b/infer/src/base/Logging.ml @@ -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)