Skip to content

Commit

Permalink
Ensure source always ends with colon
Browse files Browse the repository at this point in the history
Fixes hannesm#6.
  • Loading branch information
dra27 committed Aug 14, 2018
1 parent 6ae1918 commit 367bb4d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/logs_syslog.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ let message ?(facility = Syslog_message.System_Daemons)
(Logs.Tag.pp_set ppf tags ;
" " ^ flush ())
in
(* RFC 3164 4.1.3 notes that TAG (in this case, source) can be terminated by
any non-alphanumeric character and explictly notes that space is valid.
However, colon is more common and in at least one case the space is not
sufficient for correct parsing of the message. All this is irrelevant in
RFC 5424.
(see https://github.com/hannesm/logs-syslog/issues/6) *)
let source =
let len = String.length source in
if len > 0 && source.[len - 1] <> ':' then
source ^ ":"
else
source
in
let hdr = match header with None -> "" | Some x -> " " ^ x in
(* According to RFC 3164, source should be no more than 32 chars. *)
let message = Printf.sprintf "%s%s%s %s" source tags hdr message
and severity = slevel level
in
Expand Down

0 comments on commit 367bb4d

Please sign in to comment.