Преглед изворни кода

fix(auto_subscribe): improve log information

firest пре 3 година
родитељ
комит
d657a161db
1 измењених фајлова са 13 додато и 9 уклоњено
  1. 13 9
      apps/emqx_auto_subscribe/src/emqx_auto_subscribe_placeholder.erl

+ 13 - 9
apps/emqx_auto_subscribe/src/emqx_auto_subscribe_placeholder.erl

@@ -26,21 +26,26 @@
 generate(Topics) when is_list(Topics) ->
 generate(Topics) when is_list(Topics) ->
     [generate(Topic) || Topic <- Topics];
     [generate(Topic) || Topic <- Topics];
 
 
-generate(T0 = #{topic := Topic}) ->
-    T = maps:without([topic], T0),
+generate(T = #{topic := Topic}) ->
     T#{placeholder => generate(Topic, [])}.
     T#{placeholder => generate(Topic, [])}.
 
 
 -spec(to_topic_table(list(), map(), map()) -> list()).
 -spec(to_topic_table(list(), map(), map()) -> list()).
 to_topic_table(PHs, ClientInfo, ConnInfo) ->
 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
                    case to_topic(PlaceHolder, ClientInfo, ConnInfo, []) of
-                       {error, _} ->
+                       {error, Reason} ->
+                           ?SLOG(warning, #{msg => "auto_subscribe_ignored",
+                                            topic => RawTopic,
+                                            reason => Reason
+                                           }),
                            Acc;
                            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;
                            Acc;
                        Topic0 ->
                        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([clientid | PTs], C = #{clientid := ClientID}, Co, Res) ->
     to_topic(PTs, C, Co, [ClientID | Res]);
     to_topic(PTs, C, Co, [ClientID | Res]);
 to_topic([username | _], #{username := undefined}, _, _) ->
 to_topic([username | _], #{username := undefined}, _, _) ->
-    ?SLOG(error, #{msg => "Username undefined when auto subscribe"}),
     {error, username_undefined};
     {error, username_undefined};
 to_topic([username | PTs], C = #{username := Username}, Co, Res) ->
 to_topic([username | PTs], C = #{username := Username}, Co, Res) ->
     to_topic(PTs, C, Co, [Username | Res]);
     to_topic(PTs, C, Co, [Username | Res]);