<commit_before>%
% Copyright (c) 2016-2017 <NAME> <<EMAIL>>
% All rights reserved.
% Distributed under the terms of the MIT License. See the LICENSE file.
%
-module(lorawan_utils).

-export([throw_info/2, throw_warning/2, throw_error/2]).

-include("lorawan.hrl").

throw_info({Entity, EID}, Text) ->
    throw_event(info, Entity, EID, Text);
throw_info(Entity, Text) ->
    throw_event(info, Entity, undefined, Text).

throw_warning({Entity, EID}, Text) ->
    throw_event(warning, Entity, EID, Text);
throw_warning(Entity, Text) ->
    throw_event(warning, Entity, undefined, Text).

throw_error({Entity, EID}, Text) ->
    throw_event(error, Entity, EID, Text);
throw_error(Entity, Text) ->
    throw_event(error, Entity, undefined, Text).


throw_event(Severity, Entity, undefined, Text) ->
    lager:log(Severity, self(), "~s ~w", [Entity, Text]),
    write_event(Severity, Entity, undefined, Text);

throw_event(Severity, Entity, EID, Text) ->
    lager:log(Severity, self(), "~s ~s ~w", [Entity, lorawan_mac:binary_to_hex(EID), Text]),
    write_event(Severity, Entity, EID, Text).

write_event(Severity, Entity, EID, Text) ->
    mnesia:dirty_write(events, #event{evid= <<(erlang:system_time()):64>>,
        severity=Severity, datetime=calendar:universal_time(),
        entity=Entity, eid=EID, text=list_to_binary(io_lib:write(Text))}).

% end of file<commit_msg>Reduce the number of event messages<commit_after>%
% Copyright (c) 2016-2017 <NAME> <<EMAIL>>
% All rights reserved.
% Distributed under the terms of the MIT License. See the LICENSE file.
%
-module(lorawan_utils).

-export([throw_info/2, throw_warning/2, throw_error/2]).

-include("lorawan.hrl").

throw_info({Entity, EID}, Text) ->
    throw_event(info, Entity, EID, Text);
throw_info(Entity, Text) ->
    throw_event(info, Entity, undefined, Text).

throw_warning({Entity, EID}, Text) ->
    throw_event(warning, Entity, EID, Text);
throw_warning(Entity, Text) ->
    throw_event(warning, Entity, undefined, Text).

throw_error({Entity, EID}, Text) ->
    throw_event(error, Entity, EID, Text);
throw_error(Entity, Text) ->
    throw_event(error, Entity, undefined, Text).


throw_event(Severity, Entity, undefined, Message) ->
    lager:log(Severity, self(), "~s ~w", [Entity, Message]),
    write_event(Severity, Entity, undefined, Message);

throw_event(Severity, Entity, EID, Message) ->
    lager:log(Severity, self(), "~s ~s ~w", [Entity, lorawan_mac:binary_to_hex(EID), Message]),
    write_event(Severity, Entity, EID, Message).

write_event(Severity, Entity, EID, Message) ->
    Text = list_to_binary(io_lib:write(Message)),
    EvId = crypto:hash(md4, term_to_binary({Entity, EID, Text})),
    mnesia:dirty_write(events, #event{evid=EvId, severity=Severity,
        datetime=calendar:universal_time(), entity=Entity, eid=EID, text=Text}).

% end of file
{'fraction_non_alphanumeric': 0.15980288630763814, 'fraction_numerical': 0.008799718409010912, 'mean_word_length': 5.232456140350878, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, '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': '77260', 'n_tokens_mistral': 1021, 'n_tokens_neox': 996, 'n_words': 230}