fix logging issues
- clear dgram buffer before sending to journald - only change pretty alignment to be bigger
This commit is contained in:
parent
787dbe9d57
commit
4cc0e8a6e1
|
@ -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
|
||||
|
|
|
@ -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 =
|
||||
|
|
Loading…
Reference in New Issue