From f30b6e39db55b9c1ba6c02e5544abd2b36e598a2 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Wed, 21 Sep 2016 02:08:15 -0700 Subject: [PATCH] More robust logging to files Summary: Create the log directory even if the parent results directory does not exist. In particular, the python buck module will delete the results directory after it is created the first time, so it needs to be re-created or else there is nowhere for the log files. Reviewed By: sblackshear Differential Revision: D3896546 fbshipit-source-id: 834cf79 --- infer/src/backend/config.ml | 6 +++--- infer/src/backend/config.mli | 3 --- infer/src/backend/logging.ml | 6 ++---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/infer/src/backend/config.ml b/infer/src/backend/config.ml index 72158ab3c..dcb586bd5 100644 --- a/infer/src/backend/config.ml +++ b/infer/src/backend/config.ml @@ -1546,7 +1546,7 @@ let log_files_of_current_exe = | Print -> "print" | StatsAggregator -> "stats_agregator" | Toplevel -> "top_level" in - prefix ^ "_out", prefix ^ "_err" + prefix ^ "_out_", prefix ^ "_err_" (** should_log_exe exe = true means that files for logging in the log folder will be created and uses of Logging.out or Logging.err will log in those files *) @@ -1561,11 +1561,11 @@ let tmp_log_files_of_current_exe () = let log_dir = results_dir // log_dir_name in let out_file = if out_file_cmdline = "" then - Filename.temp_file ~temp_dir:log_dir out_name "" + Filename.temp_file ~temp_dir:log_dir out_name ".log" else out_file_cmdline in let err_file = if err_file_cmdline = "" then - Filename.temp_file ~temp_dir:log_dir err_name "" + Filename.temp_file ~temp_dir:log_dir err_name ".log" else err_file_cmdline in out_file, err_file diff --git a/infer/src/backend/config.mli b/infer/src/backend/config.mli index dce544bab..c96489106 100644 --- a/infer/src/backend/config.mli +++ b/infer/src/backend/config.mli @@ -310,9 +310,6 @@ val curr_language : language ref val print_usage_exit : unit -> 'a -(** Name of files for logging the output in the current executable *) -val log_files_of_current_exe : string * string - (** Name of current temporary files for logging the output in the current executable *) val tmp_log_files_of_current_exe : unit -> string * string diff --git a/infer/src/backend/logging.ml b/infer/src/backend/logging.ml index 936d32bd9..c771f5bec 100644 --- a/infer/src/backend/logging.ml +++ b/infer/src/backend/logging.ml @@ -87,11 +87,9 @@ let out_formatter, err_formatter = with Sys_error _ -> failwithf "@.ERROR: cannot open output file %s@." fname in - if Sys.file_exists Config.results_dir - && Sys.is_directory Config.results_dir - && Config.should_log_current_exe - then + if Config.should_log_current_exe then let log_dir = Config.results_dir // Config.log_dir_name in + create_dir Config.results_dir; create_dir log_dir; let out_file, err_file = Config.tmp_log_files_of_current_exe () in let out_fmt, out_chan = open_output_file out_file in