Skip to content

Commit 043e6bd

Browse files
authored
Revert "log/debug: use Ptime's rfc3339 formatting when logging to stdout (#7014)
It changes behaviour of the audit_log endpoint This reverts commit ab802e6.
2 parents 31785f2 + f55f5a8 commit 043e6bd

5 files changed

Lines changed: 14 additions & 13 deletions

File tree

ocaml/idl/ocaml_backend/dune

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
(libraries
55
astring
66
cmdliner
7-
fmt
8-
ptime.clock
97
uuidm
108
xapi-consts
119
xapi-datamodel

ocaml/idl/ocaml_backend/gen_rbac.ml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ let internal_role_local_root = "_local_root_"
3434

3535
(* the output of this function is used as input by the automatic tests *)
3636
let writer_csv static_permissions_roles =
37-
let now =
38-
let now = Ptime_clock.now () in
39-
let str = Fmt.str "%a" Ptime.(pp_rfc3339 ~frac_s:3 ~tz_offset_s:0 ()) now in
40-
(* remove separators between Year, Month, and Day; to keep old logging format *)
41-
Astring.String.filter (function '-' -> false | _ -> true) str
42-
in
43-
Printf.sprintf "%s,PERMISSION/ROLE,%s\n" now
37+
Printf.sprintf "%s,PERMISSION/ROLE,%s\n"
38+
(let t = Debug.gettimestring () in
39+
String.sub t 0 (String.length t - 1)
40+
)
4441
(* role titles are ordered by roles in roles_all *)
4542
(List.fold_left (fun rr r -> rr ^ r ^ ",") "" Datamodel_roles.roles_all)
4643
^ List.fold_left

ocaml/libs/log/debug.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ let tasks : task ThreadLocalTable.t = ThreadLocalTable.make ()
7474
let names : string ThreadLocalTable.t = ThreadLocalTable.make ()
7575

7676
let gettimestring () =
77-
let now = Ptime_clock.now () in
78-
Fmt.str "%a|" Ptime.(pp_rfc3339 ~frac_s:3 ~tz_offset_s:0 ()) now
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))
7984

8085
(** [escape str] efficiently escapes non-printable characters and in addition
8186
the backslash character. The function is efficient in the sense that it will

ocaml/libs/log/debug.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ val set_remote_context : string option -> unit
3434

3535
module type BRAND = sig val name : string end
3636

37+
val gettimestring : unit -> string
38+
(** The current time of day in a format suitable for logging *)
39+
3740
val set_facility : Syslog.facility -> unit
3841
(** Set the syslog facility that will be used by this program. *)
3942

ocaml/libs/log/dune

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
fmt
1111
mtime
1212
logs
13-
ptime
14-
ptime.clock
1513
threads.posix
1614
unix
1715
xapi-log.backtrace

0 commit comments

Comments
 (0)