Skip to content

Commit c83d688

Browse files
committed
Revert "log/debug: use Ptime's rfc3339 formatting when logging to stdout"
It changes behaviour of the audit_log endpoint This reverts commit 2edf203. Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent 0c4204a commit c83d688

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
@@ -31,6 +31,9 @@ val with_thread_named : string -> ('a -> 'b) -> 'a -> 'b
3131

3232
module type BRAND = sig val name : string end
3333

34+
val gettimestring : unit -> string
35+
(** The current time of day in a format suitable for logging *)
36+
3437
val set_facility : Syslog.facility -> unit
3538
(** Set the syslog facility that will be used by this program. *)
3639

ocaml/libs/log/dune

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
fmt
1010
mtime
1111
logs
12-
ptime
13-
ptime.clock
1412
threads.posix
1513
xapi-backtrace
1614
unix

0 commit comments

Comments
 (0)