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(<<>>) ->
|
||||
ok;
|
||||
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).
|
||||
set_metadata_peername(Peername) ->
|
||||
|
|
|
@ -145,17 +145,19 @@ handler_id(?TOPIC_TRACE(Topic)) ->
|
|||
handler_id(?CLIENT_TRACE(ClientId)) ->
|
||||
list_to_atom(?CLIENT_TRACE_ID(handler_name(ClientId))).
|
||||
|
||||
filter_by_meta_key(#{meta:=Meta}=LogEvent, {MetaKey, MetaValue}) ->
|
||||
case maps:find(MetaKey, Meta) of
|
||||
{ok, MetaValue} -> LogEvent;
|
||||
{ok, Topic} when MetaKey =:= topic ->
|
||||
case emqx_topic:match(Topic, MetaValue) of
|
||||
true -> LogEvent;
|
||||
false -> ignore
|
||||
end;
|
||||
_ -> ignore
|
||||
filter_by_meta_key(#{meta := Meta} = Log, {Key, Value}) ->
|
||||
case is_meta_match(Key, Value, Meta) of
|
||||
true -> Log;
|
||||
false -> ignore
|
||||
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) ->
|
||||
case byte_size(Bin) of
|
||||
Size when Size =< 200 -> binary_to_list(Bin);
|
||||
|
|
|
@ -33,7 +33,6 @@ init_per_suite(Config) ->
|
|||
end_per_suite(_Config) ->
|
||||
emqx_ct_helpers:stop_apps([]).
|
||||
|
||||
|
||||
t_start_traces(_Config) ->
|
||||
{ok, T} = emqtt:start_link([{host, "localhost"},
|
||||
{clientid, <<"client">>},
|
||||
|
|
Loading…
Reference in New Issue