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;
|
mutex : Mutex.t;
|
||||||
sock_fd : Unix.file_descr;
|
sock_fd : Unix.file_descr;
|
||||||
dest : Unix.sockaddr;
|
dest : Unix.sockaddr;
|
||||||
dgram : Buffer.t;
|
buf : Buffer.t;
|
||||||
}
|
}
|
||||||
|
|
||||||
let make ?(path = default_socket_path) () = {
|
let make ?(path = default_socket_path) () = {
|
||||||
mutex = Mutex.create ();
|
mutex = Mutex.create ();
|
||||||
sock_fd = Unix.socket PF_UNIX SOCK_DGRAM 0 ~cloexec:true;
|
sock_fd = Unix.socket PF_UNIX SOCK_DGRAM 0 ~cloexec:true;
|
||||||
dest = ADDR_UNIX path;
|
dest = ADDR_UNIX path;
|
||||||
dgram = Buffer.create 256;
|
buf = Buffer.create 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
let add_field dgram key value =
|
let add_field dgram key value =
|
||||||
|
@ -38,9 +38,10 @@ let syslog_priority = function
|
||||||
let writer t ~ts ~ns ~lvl msg =
|
let writer t ~ts ~ns ~lvl msg =
|
||||||
let dgram =
|
let dgram =
|
||||||
Mutex.protect t.mutex @@ fun () ->
|
Mutex.protect t.mutex @@ fun () ->
|
||||||
|
Buffer.clear t.buf;
|
||||||
ignore ts;
|
ignore ts;
|
||||||
add_field t.dgram "MESSAGE" (Printf.sprintf "%s: %s" ns msg);
|
add_field t.buf "MESSAGE" (Printf.sprintf "%s: %s" ns msg);
|
||||||
add_field t.dgram "PRIORITY" (syslog_priority lvl);
|
add_field t.buf "PRIORITY" (syslog_priority lvl);
|
||||||
Buffer.to_bytes t.dgram
|
Buffer.to_bytes t.buf
|
||||||
in
|
in
|
||||||
Unix.sendto t.sock_fd dgram 0 (Bytes.length dgram) [] t.dest |> ignore
|
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 f mask = t.flags land mask = mask in
|
||||||
let align bp =
|
let align bp =
|
||||||
let n = t.align_to - Buffer.length bp in
|
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
|
n
|
||||||
in
|
in
|
||||||
let indent bp =
|
let indent bp =
|
||||||
|
|
Loading…
Reference in New Issue