diff --git a/src/logs_syslog_unix.ml b/src/logs_syslog_unix.ml index a605914..e39c68e 100644 --- a/src/logs_syslog_unix.ml +++ b/src/logs_syslog_unix.ml @@ -134,5 +134,21 @@ let unix_reporter | None -> (fun msg -> msg), Unix.SOCK_DGRAM in let sa = Unix.ADDR_UNIX socket in - let encode = Syslog_message.encode_local in + let encode ?(len=1024) (msg : Syslog_message.t) = + let open Syslog_message in + let open Astring in + let f v g = + if v = g then failwith "Invalid value" else (Obj.magic v : int) + in + let facse = + f msg.facility Invalid_Facility * 8 + f msg.severity Invalid_Severity + and ts = Rfc3164_Timestamp.encode msg.timestamp + in + let msgstr = Printf.sprintf "<%d>%s %s" facse ts msg.message + in + if len > 0 && String.length msgstr > len then + String.with_range ~first:0 ~len:len msgstr + else + msgstr + in conn_reporter Unix.PF_UNIX socket_type sa truncate frame encode "localhost"