anchor.diff:           ,facility_to_int/1
            ,severity_to_int/1
            ,fmt/7
  +         ,rfc5424/1
  +         ,rfc5424/8
           ]).
   
   -type syslog_msg() :: {0..128, 0..7,
  
positive.code:      ,{22, local6, "local use 6  (local6)"}
       ,{23, local7, "local use 7  (local7)"}].
  
  facility_to_int(I) when is_integer(I) ->
      I;
  facility_to_int(A) when is_atom(A) ->
      element(1, lists:keyfind(A, 2, facilities())).
  
  severities() ->
      [ {0, emergency, "Emergency: system is unusable"}
       ,{1, alert, "Alert: action must be taken immediately"}
  
negative.code:     [ <<"<">>, pri(Facility, Severity), <<">1 ">>,
        Time, $\s, Token, $\s, Source, $\s, Process, <<" - - ">>, Msg ].
  
  rfc5424({Facility, Severity, Time, Source, Process, Msg}) ->
      rfc5424(Facility, Severity, Time, Source,
              Process, undefined, undefined, Msg).
  
  rfc5424(Facility, Severity, Time, Host, AppName, ProcID, MsgID, Msg) ->
      [ <<"<">>, pri(Facility, Severity), <<">1">>,
        [ [$\s, nvl(Item)]
          || Item <- [Time, Host, AppName, ProcID, MsgID] ],
        case Msg of
            undefined -> [];
            _ -> [$\s, Msg]
        end
      ].
  
  nvl(undefined) -> $-;
  nvl(Val) -> Val.
  
  
  from_msg(Msg) when is_binary(Msg) ->
      %% <40>1 2010-11-10T17:16:33-08:00 domU-12-31-39-13-74-02 t.xxx web.1 - - State changed from created to starting
      %% <PriFac>1 Time Host Token Process - - Msg
  