@@ -74,13 +74,8 @@ let tasks : task ThreadLocalTable.t = ThreadLocalTable.make ()
7474let names : string ThreadLocalTable.t = ThreadLocalTable. make ()
7575
7676let gettimestring () =
77- let time = Unix. gettimeofday () in
78- let tm = Unix. gmtime time in
79- let msec = time -. floor time in
80- Printf. sprintf " %d%.2d%.2dT%.2d:%.2d:%.2d.%.3dZ|" (1900 + tm.Unix. tm_year)
81- (tm.Unix. tm_mon + 1 ) tm.Unix. tm_mday tm.Unix. tm_hour tm.Unix. tm_min
82- tm.Unix. tm_sec
83- (int_of_float (1000.0 *. msec))
77+ let now = Ptime_clock. now () in
78+ Fmt. str " %a|" Ptime. (pp_rfc3339 ~frac_s: 3 ~tz_offset_s: 0 () ) now
8479
8580(* * [escape str] efficiently escapes non-printable characters and in addition
8681 the backslash character. The function is efficient in the sense that it will
@@ -216,20 +211,14 @@ let init_logs () =
216211 calling [output_log] too often. *)
217212 Logs. set_level (Some Logs. Warning )
218213
219- let rec split_c c str =
220- try
221- let i = String. index str c in
222- String. sub str 0 i
223- :: split_c c (String. sub str (i + 1 ) (String. length str - i - 1 ))
224- with Not_found -> [str]
225-
226214let log_backtrace_exn ?(level = Syslog. Err ) ?(msg = " error" ) exn bt =
227- (* We already got the backtrace in the `bt` argument when called from with_thread_associated.
228- Log that, and remove `exn` from the backtraces table.
229- If with_backtraces was not nested then looking at `bt` is the only way to get
230- a proper backtrace, otherwise exiting from `with_backtraces` would've removed the backtrace
231- from the thread-local backtraces table, and we'd always just log a message complaining about
232- with_backtraces not being called, which is not true because it was.
215+ (* We already got the backtrace in the `bt` argument when called from
216+ with_thread_associated. Log that, and remove `exn` from the backtraces
217+ table. If with_backtraces was not nested then looking at `bt` is the only
218+ way to get a proper backtrace, otherwise exiting from `with_backtraces`
219+ would've removed the backtrace from the thread-local backtraces table, and
220+ we'd always just log a message complaining about with_backtraces not being
221+ called, which is not true because it was.
233222 *)
234223 let bt' = Backtrace. remove exn in
235224 (* bt could be empty, but bt' would contain a non-empty warning, so compare 'bt' here *)
@@ -239,7 +228,7 @@ let log_backtrace_exn ?(level = Syslog.Err) ?(msg = "error") exn bt =
239228 else
240229 bt
241230 in
242- let all = split_c '\n' Backtrace. (to_string_hum bt) in
231+ let all = String. split_on_char '\n' Backtrace. (to_string_hum bt) in
243232 (* Write to the log line at a time *)
244233 output_log " backtrace" level msg
245234 (Printf. sprintf " Raised %s" (Printexc. to_string exn )) ;
0 commit comments