Skip to content

Commit

Permalink
write to log-dir with timestamp filename
Browse files Browse the repository at this point in the history
  • Loading branch information
edchapman88 committed Oct 24, 2024
1 parent db23d6a commit cc58cd4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let usage_msg =
"\n\
\ Usage:\n\
\ getting [-allow-select-backend] [-ignore-fd-limit] [-no-tls] \
[-serial-debug] [-rect-wave] [-l <log-file>] [-p <serial-port>] [-h \
[-serial-debug] [-rect-wave] [-l <log-dir>] [-p <serial-port>] [-h \
<host-file>] [-i <interval>] <uri> \n\n\
\ Example:\n\
\ getting https://serving.local\n\n\
Expand All @@ -14,7 +14,7 @@ let tls = ref true
let include_debug = ref false
let rect_wave = ref false
let serial_port = ref "/dev/stdout"
let log_file = ref ""
let log_dir = ref ""
let host_file = ref ""
let request_interval = ref 1.
let host = ref ""
Expand Down Expand Up @@ -44,8 +44,8 @@ let speclist =
In the absence of this flag a load with a constant request rate is \
applied.\n" );
( "-l",
Arg.Set_string log_file,
": Optionally write to a log file at the specified location with \
Arg.Set_string log_dir,
": Optionally write a log file in the specified directory with \
information about the success or failure of each request.\n" );
( "-p",
Arg.Set_string serial_port,
Expand All @@ -65,7 +65,7 @@ let serial_debug () = !include_debug
let rectangular_wave () = !rect_wave
let r_interval () = !request_interval
let target_uri () = Uri.of_string !host
let log_path () = if String.length !log_file == 0 then None else Some !log_file
let log_path () = if String.length !log_dir == 0 then None else Some !log_dir

let arg_parse () =
let anon_fun target_host = host := target_host in
Expand Down
9 changes: 8 additions & 1 deletion lib/log.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
let file_of_path (path : string) =
let path = if String.ends_with ~suffix:"/" path then path else path ^ "/" in
(* Read and write for all users.*)
Unix.mkdir path 0o777;
let open Core.Time_float in
open_out (path ^ to_filename_string ~zone:Zone.utc (now ()) ^ ".txt")

let oc = ref None
let init_oc path = oc := Some (open_out path)
let init_oc path = oc := Some (file_of_path path)

let rec write_of_score path score =
match !oc with
Expand Down

0 comments on commit cc58cd4

Please sign in to comment.