fix(log): client id as string for log metadata
so it does not print <<"...">> to the logs
This commit is contained in:
parent
fd69969014
commit
3547dc4c93
|
@ -138,7 +138,15 @@ critical(Metadata, Format, Args) when is_map(Metadata) ->
|
||||||
set_metadata_clientid(<<>>) ->
|
set_metadata_clientid(<<>>) ->
|
||||||
ok;
|
ok;
|
||||||
set_metadata_clientid(ClientId) ->
|
set_metadata_clientid(ClientId) ->
|
||||||
set_proc_metadata(#{clientid => ClientId}).
|
try
|
||||||
|
%% try put string format client-id metadata so
|
||||||
|
%% so the log is not like <<"...">>
|
||||||
|
Id = unicode:characters_to_list(ClientId, utf8),
|
||||||
|
set_proc_metadata(#{clientid => Id})
|
||||||
|
catch
|
||||||
|
_: _->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
-spec(set_metadata_peername(peername_str()) -> ok).
|
-spec(set_metadata_peername(peername_str()) -> ok).
|
||||||
set_metadata_peername(Peername) ->
|
set_metadata_peername(Peername) ->
|
||||||
|
|
|
@ -145,17 +145,19 @@ handler_id(?TOPIC_TRACE(Topic)) ->
|
||||||
handler_id(?CLIENT_TRACE(ClientId)) ->
|
handler_id(?CLIENT_TRACE(ClientId)) ->
|
||||||
list_to_atom(?CLIENT_TRACE_ID(handler_name(ClientId))).
|
list_to_atom(?CLIENT_TRACE_ID(handler_name(ClientId))).
|
||||||
|
|
||||||
filter_by_meta_key(#{meta:=Meta}=LogEvent, {MetaKey, MetaValue}) ->
|
filter_by_meta_key(#{meta := Meta} = Log, {Key, Value}) ->
|
||||||
case maps:find(MetaKey, Meta) of
|
case is_meta_match(Key, Value, Meta) of
|
||||||
{ok, MetaValue} -> LogEvent;
|
true -> Log;
|
||||||
{ok, Topic} when MetaKey =:= topic ->
|
false -> ignore
|
||||||
case emqx_topic:match(Topic, MetaValue) of
|
|
||||||
true -> LogEvent;
|
|
||||||
false -> ignore
|
|
||||||
end;
|
|
||||||
_ -> ignore
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
is_meta_match(clientid, ClientId, #{clientid := ClientIdStr}) ->
|
||||||
|
ClientId =:= iolist_to_binary(ClientIdStr);
|
||||||
|
is_meta_match(topic, TopicFilter, #{topic := TopicMeta}) ->
|
||||||
|
emqx_topic:match(TopicMeta, TopicFilter);
|
||||||
|
is_meta_match(_, _, _) ->
|
||||||
|
false.
|
||||||
|
|
||||||
handler_name(Bin) ->
|
handler_name(Bin) ->
|
||||||
case byte_size(Bin) of
|
case byte_size(Bin) of
|
||||||
Size when Size =< 200 -> binary_to_list(Bin);
|
Size when Size =< 200 -> binary_to_list(Bin);
|
||||||
|
|
|
@ -32,7 +32,6 @@ init_per_suite(Config) ->
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
emqx_ct_helpers:stop_apps([]).
|
emqx_ct_helpers:stop_apps([]).
|
||||||
|
|
||||||
|
|
||||||
t_start_traces(_Config) ->
|
t_start_traces(_Config) ->
|
||||||
{ok, T} = emqtt:start_link([{host, "localhost"},
|
{ok, T} = emqtt:start_link([{host, "localhost"},
|
||||||
|
@ -89,4 +88,4 @@ t_start_traces(_Config) ->
|
||||||
emqtt:disconnect(T),
|
emqtt:disconnect(T),
|
||||||
|
|
||||||
emqx_logger:set_log_level(warning).
|
emqx_logger:set_log_level(warning).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue