From d657a161dbe10caa11061bb5175cfa5cfad9adcc Mon Sep 17 00:00:00 2001 From: firest Date: Tue, 22 Mar 2022 15:02:25 +0800 Subject: [PATCH] fix(auto_subscribe): improve log information --- .../src/emqx_auto_subscribe_placeholder.erl | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/emqx_auto_subscribe/src/emqx_auto_subscribe_placeholder.erl b/apps/emqx_auto_subscribe/src/emqx_auto_subscribe_placeholder.erl index 8814edf62..582d4ef5e 100644 --- a/apps/emqx_auto_subscribe/src/emqx_auto_subscribe_placeholder.erl +++ b/apps/emqx_auto_subscribe/src/emqx_auto_subscribe_placeholder.erl @@ -26,21 +26,26 @@ generate(Topics) when is_list(Topics) -> [generate(Topic) || Topic <- Topics]; -generate(T0 = #{topic := Topic}) -> - T = maps:without([topic], T0), +generate(T = #{topic := Topic}) -> T#{placeholder => generate(Topic, [])}. -spec(to_topic_table(list(), map(), map()) -> list()). to_topic_table(PHs, ClientInfo, ConnInfo) -> - Fold = fun(#{qos := Qos, rh := RH, rap := RAP, nl := NL, placeholder := PlaceHolder}, Acc) -> + Fold = fun(#{qos := Qos, rh := RH, rap := RAP, nl := NL, + placeholder := PlaceHolder, topic := RawTopic + }, + Acc) -> case to_topic(PlaceHolder, ClientInfo, ConnInfo, []) of - {error, _} -> + {error, Reason} -> + ?SLOG(warning, #{msg => "auto_subscribe_ignored", + topic => RawTopic, + reason => Reason + }), Acc; <<>> -> - ?SLOG(warning, #{msg => "Topic can't be empty", - clientinfo => ClientInfo, - conninfo => ConnInfo, - placeholder => PlaceHolder + ?SLOG(warning, #{msg => "auto_subscribe_ignored", + topic => RawTopic, + reason => empty_topic }), Acc; Topic0 -> @@ -77,7 +82,6 @@ to_topic([Binary | PTs], C, Co, Res) when is_binary(Binary) -> to_topic([clientid | PTs], C = #{clientid := ClientID}, Co, Res) -> to_topic(PTs, C, Co, [ClientID | Res]); to_topic([username | _], #{username := undefined}, _, _) -> - ?SLOG(error, #{msg => "Username undefined when auto subscribe"}), {error, username_undefined}; to_topic([username | PTs], C = #{username := Username}, Co, Res) -> to_topic(PTs, C, Co, [Username | Res]);