only log to analyzer_err and analyzer_out files in developer mode

Reviewed By: jberdine

Differential Revision: D2742111

fb-gh-sync-id: 40d5cb3
master
Samuel Blackshear 9 years ago committed by facebook-github-bot-5
parent 742cb4146e
commit 546eaa0eaa

@ -667,9 +667,31 @@ let close_output_file = function
| None -> () | None -> ()
| Some (fmt, cout) -> close_out cout | Some (fmt, cout) -> close_out cout
let log_dir_name = "log" let setup_logging () =
let analyzer_out_name = "analyzer_out" if !Config.developer_mode then
let analyzer_err_name = "analyzer_err" let log_dir_name = "log" in
let analyzer_out_name = "analyzer_out" in
let analyzer_err_name = "analyzer_err" in
let log_dir = DB.filename_to_string (DB.Results_dir.path_to_filename DB.Results_dir.Abs_root [log_dir_name]) in
DB.create_dir log_dir;
let analyzer_out_file =
if !out_file_cmdline = "" then Filename.concat log_dir analyzer_out_name
else !out_file_cmdline in
let analyzer_err_file =
if !err_file_cmdline = "" then Filename.concat log_dir analyzer_err_name
else !err_file_cmdline in
let analyzer_out_of = open_output_file Logging.set_out_formatter analyzer_out_file in
let analyzer_err_of = open_output_file Logging.set_err_formatter analyzer_err_file in
analyzer_out_of, analyzer_err_of
else None, None
let teardown_logging analyzer_out_of analyzer_err_of =
if !Config.developer_mode then
begin
L.flush_streams ();
close_output_file analyzer_out_of;
close_output_file analyzer_err_of;
end
(** Compute clusters when on-demand is active. (** Compute clusters when on-demand is active.
Each cluster will contain only the name of the directory for a file. *) Each cluster will contain only the name of the directory for a file. *)
@ -703,16 +725,7 @@ let () =
if !allow_specs_cleanup = true && !incremental_mode = ANALYZE_ALL && !cluster_cmdline = None then if !allow_specs_cleanup = true && !incremental_mode = ANALYZE_ALL && !cluster_cmdline = None then
DB.Results_dir.clean_specs_dir (); DB.Results_dir.clean_specs_dir ();
let log_dir = DB.filename_to_string (DB.Results_dir.path_to_filename DB.Results_dir.Abs_root [log_dir_name]) in let analyzer_out_of, analyzer_err_of = setup_logging () in
DB.create_dir log_dir;
let analyzer_out_file =
if !out_file_cmdline = "" then Filename.concat log_dir analyzer_out_name
else !out_file_cmdline in
let analyzer_err_file =
if !err_file_cmdline = "" then Filename.concat log_dir analyzer_err_name
else !err_file_cmdline in
let analyzer_out_of = open_output_file Logging.set_out_formatter analyzer_out_file in
let analyzer_err_of = open_output_file Logging.set_err_formatter analyzer_err_file in
if (!Config.curr_language = Config.C_CPP) then Mleak_buckets.init_buckets !ml_buckets_arg; if (!Config.curr_language = Config.C_CPP) then Mleak_buckets.init_buckets !ml_buckets_arg;
process_cluster_cmdline_exit (); process_cluster_cmdline_exit ();
@ -744,7 +757,5 @@ let () =
let tot_clusters = IList.length clusters in let tot_clusters = IList.length clusters in
Fork.tot_files := IList.fold_left (fun n cluster -> n + IList.length cluster) 0 clusters; Fork.tot_files := IList.fold_left (fun n cluster -> n + IList.length cluster) 0 clusters;
IList.iter (analyze_cluster (ref 0) tot_clusters) clusters; IList.iter (analyze_cluster (ref 0) tot_clusters) clusters;
L.flush_streams (); teardown_logging analyzer_out_of analyzer_err_of;
close_output_file analyzer_out_of;
close_output_file analyzer_err_of;
if !cluster_cmdline = None then L.stdout "Analysis finished in %as@." pp_elapsed_time () if !cluster_cmdline = None then L.stdout "Analysis finished in %as@." pp_elapsed_time ()

@ -86,8 +86,11 @@ let set_err_formatter fmt =
(** Flush the current streams *) (** Flush the current streams *)
let flush_streams () = let flush_streams () =
F.fprintf !current_out_formatter "@?"; if !Config.developer_mode then
F.fprintf !current_err_formatter "@?" begin
F.fprintf !current_out_formatter "@?";
F.fprintf !current_err_formatter "@?"
end
(** extend the current print log *) (** extend the current print log *)
let add_print_action pact = let add_print_action pact =
@ -103,21 +106,24 @@ let get_delayed_prints () =
!delayed_actions !delayed_actions
let do_print fmt fmt_string = let do_print fmt fmt_string =
F.fprintf fmt fmt_string if !Config.developer_mode then
F.fprintf fmt fmt_string
else
F.ifprintf fmt fmt_string
(** print on the out stream *) (** print to the current out stream (note: only prints in developer mode) *)
let out fmt_string = let out fmt_string =
do_print !current_out_formatter fmt_string do_print !current_out_formatter fmt_string
(** print on the err stream *) (** print to the current err stream (note: only prints in developer mode) *)
let err fmt_string = let err fmt_string =
do_print !current_err_formatter fmt_string do_print !current_err_formatter fmt_string
(** print immediately to standard error *) (** print immediately to standard error (note: only prints in developer mode) *)
let stderr fmt_string = let stderr fmt_string =
do_print F.err_formatter fmt_string do_print F.err_formatter fmt_string
(** print immediately to standard output *) (** print immediately to standard output (note: only prints in developer mode) *)
let stdout fmt_string = let stdout fmt_string =
do_print F.std_formatter fmt_string do_print F.std_formatter fmt_string

@ -68,16 +68,16 @@ val get_delayed_prints : unit -> print_action list
(** reset the delayed print actions *) (** reset the delayed print actions *)
val reset_delayed_prints : unit -> unit val reset_delayed_prints : unit -> unit
(** print to the current out stream *) (** print to the current out stream (note: only prints in developer mode) *)
val out : ('a, Format.formatter, unit) format -> 'a val out : ('a, Format.formatter, unit) format -> 'a
(** print to the current err stream *) (** print to the current err stream (note: only prints in developer mode) *)
val err : ('a, Format.formatter, unit) format -> 'a val err : ('a, Format.formatter, unit) format -> 'a
(** print immediately to standard error *) (** print immediately to standard error (note: only prints in developer mode) *)
val stderr : ('a, Format.formatter, unit) format -> 'a val stderr : ('a, Format.formatter, unit) format -> 'a
(** print immediately to standard output *) (** print immediately to standard output (note: only prints in developer mode) *)
val stdout : ('a, Format.formatter, unit) format -> 'a val stdout : ('a, Format.formatter, unit) format -> 'a
(** Get the current out formatter *) (** Get the current out formatter *)

Loading…
Cancel
Save