<commit_before>%% @copyright <NAME>
%% @author <NAME> <<EMAIL>>
%% @version {@vsn}, {@date} {@time}
%% @doc Syslog message formatting utilities.
%% @end
-module(logplex_syslog_utils).

-export([to_msg/1
         ,to_msg/2
         ,from_msg/1
         ,frame/1
         ,datetime/1
         ,facility_to_int/1
         ,severity_to_int/1
         ,fmt/7
         ,rfc5424/1
         ,rfc5424/8
        ]).

-type syslog_msg() :: {0..128, 0..7,
                       Time::iolist(), Source::iolist(),
                       Process::iolist(), Msg::iolist()}.

-export_type([ syslog_msg/0 ]).

-spec to_msg(syslog_msg()) -> iolist().
to_msg({Facility, Severity, Time, Source, Process, Msg})
  when is_integer(Facility), is_integer(Severity) ->
    [ <<"<">>, pri(Facility, Severity), <<">1 ">>,
      Time, $\s, Source, $\s, Process, <<" - - ">>, Msg ].

-spec to_msg(syslog_msg(), iolist() | binary()) -> iolist().
to_msg({Facility, Severity, Time, Source, Process, Msg}, Token) ->
    [ <<"<">>, pri(Facility, Severity), <<">1 ">>,
      Time, $\s, Token, $\s, Source, $\s, Process, <<" - - ">>, Msg , $\n].

rfc5424({Facility, Severity, Time, Source, Process, Msg}) -><commit_msg>Remove dead to_msg/1 from syslog_utils.<commit_after>%% @copyright <NAME>
%% @author <NAME> <<EMAIL>>
%% @version {@vsn}, {@date} {@time}
%% @doc Syslog message formatting utilities.
%% @end
-module(logplex_syslog_utils).

-export([to_msg/2
         ,from_msg/1
         ,frame/1
         ,datetime/1
         ,facility_to_int/1
         ,severity_to_int/1
         ,fmt/7
         ,rfc5424/1
         ,rfc5424/8
        ]).

-type syslog_msg() :: {0..128, 0..7,
                       Time::iolist(), Source::iolist(),
                       Process::iolist(), Msg::iolist()}.

-export_type([ syslog_msg/0 ]).

-spec to_msg(syslog_msg(), iolist() | binary()) -> iolist().
to_msg({Facility, Severity, Time, Source, Process, Msg}, Token) ->
    [ <<"<">>, pri(Facility, Severity), <<">1 ">>,
      Time, $\s, Token, $\s, Source, $\s, Process, <<" - - ">>, Msg , $\n].

rfc5424({Facility, Severity, Time, Source, Process, Msg}) ->
{'fraction_non_alphanumeric': 0.21469194312796208, 'fraction_numerical': 0.02890995260663507, 'mean_word_length': 2.571912013536379, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4485090', 'n_tokens_mistral': 822, 'n_tokens_neox': 781, 'n_words': 158}