From 4cc0e8a6e1e2b79fcb9643670b5dffe183c6a31b Mon Sep 17 00:00:00 2001 From: tali Date: Thu, 1 Feb 2024 13:27:19 -0500 Subject: [PATCH] fix logging issues - clear dgram buffer before sending to journald - only change pretty alignment to be bigger --- lib/logging/journald.ml | 11 ++++++----- lib/logging/pretty.ml | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/logging/journald.ml b/lib/logging/journald.ml index 2f08f79..87980bd 100644 --- a/lib/logging/journald.ml +++ b/lib/logging/journald.ml @@ -6,14 +6,14 @@ type t = { mutex : Mutex.t; sock_fd : Unix.file_descr; dest : Unix.sockaddr; - dgram : Buffer.t; + buf : Buffer.t; } let make ?(path = default_socket_path) () = { mutex = Mutex.create (); sock_fd = Unix.socket PF_UNIX SOCK_DGRAM 0 ~cloexec:true; dest = ADDR_UNIX path; - dgram = Buffer.create 256; + buf = Buffer.create 256; } let add_field dgram key value = @@ -38,9 +38,10 @@ let syslog_priority = function let writer t ~ts ~ns ~lvl msg = let dgram = Mutex.protect t.mutex @@ fun () -> + Buffer.clear t.buf; ignore ts; - add_field t.dgram "MESSAGE" (Printf.sprintf "%s: %s" ns msg); - add_field t.dgram "PRIORITY" (syslog_priority lvl); - Buffer.to_bytes t.dgram + add_field t.buf "MESSAGE" (Printf.sprintf "%s: %s" ns msg); + add_field t.buf "PRIORITY" (syslog_priority lvl); + Buffer.to_bytes t.buf in Unix.sendto t.sock_fd dgram 0 (Bytes.length dgram) [] t.dest |> ignore diff --git a/lib/logging/pretty.ml b/lib/logging/pretty.ml index cab42eb..c8adbb7 100644 --- a/lib/logging/pretty.ml +++ b/lib/logging/pretty.ml @@ -95,7 +95,7 @@ let writer t ~ts ~ns ~lvl msg = let f mask = t.flags land mask = mask in let align bp = let n = t.align_to - Buffer.length bp in - t.align_to <- Buffer.length bp; + t.align_to <- max t.align_to (Buffer.length bp); n in let indent bp =