Browse Source

fix(log): two minor logging related fixes

firest 1 year ago
parent
commit
aa6fa2f41c

+ 1 - 1
apps/emqx/src/emqx_banned.erl

@@ -519,7 +519,7 @@ on_banned(#banned{who = {clientid, ClientId}}) ->
             clientid => ClientId
         }
     ),
-    emqx_cm:kick_session(ClientId),
+    emqx_cm:try_kick_session(ClientId),
     ok;
 on_banned(_) ->
     ok.

+ 26 - 14
apps/emqx/src/emqx_cm.erl

@@ -54,6 +54,7 @@
     takeover_session_end/1,
     kick_session/1,
     kick_session/2,
+    try_kick_session/1,
     takeover_kick/1
 ]).
 
@@ -600,20 +601,15 @@ kick_session(ClientId) ->
             ),
             ok;
         ChanPids ->
-            case length(ChanPids) > 1 of
-                true ->
-                    ?SLOG(
-                        warning,
-                        #{
-                            msg => "more_than_one_channel_found",
-                            chan_pids => ChanPids
-                        },
-                        #{clientid => ClientId}
-                    );
-                false ->
-                    ok
-            end,
-            lists:foreach(fun(Pid) -> kick_session(ClientId, Pid) end, ChanPids)
+            kick_session_chans(ClientId, ChanPids)
+    end.
+
+try_kick_session(ClientId) ->
+    case lookup_channels(ClientId) of
+        [] ->
+            ok;
+        ChanPids ->
+            kick_session_chans(ClientId, ChanPids)
     end.
 
 %% @doc Is clean start?
@@ -814,3 +810,19 @@ get_connected_client_count() ->
         undefined -> 0;
         Size -> Size
     end.
+
+kick_session_chans(ClientId, ChanPids) ->
+    case length(ChanPids) > 1 of
+        true ->
+            ?SLOG(
+                warning,
+                #{
+                    msg => "more_than_one_channel_found",
+                    chan_pids => ChanPids
+                },
+                #{clientid => ClientId}
+            );
+        false ->
+            ok
+    end,
+    lists:foreach(fun(Pid) -> kick_session(ClientId, Pid) end, ChanPids).

+ 0 - 1
apps/emqx_conf/src/emqx_conf_schema.erl

@@ -1390,7 +1390,6 @@ log_handler_common_confs(Handler, Default) ->
         {"payload_encode",
             sc(hoconsc:enum([hex, text, hidden]), #{
                 default => text,
-                importance => ?IMPORTANCE_HIDDEN,
                 desc => ?DESC(emqx_schema, fields_trace_payload_encode)
             })}
     ].

+ 3 - 1
apps/emqx_conf/test/emqx_conf_logger_SUITE.erl

@@ -78,7 +78,8 @@ t_log_conf(_Conf) ->
         <<"rotation_size">> => <<"50MB">>,
         <<"time_offset">> => <<"system">>,
         <<"path">> => <<"log/emqx.log">>,
-        <<"timestamp_format">> => <<"auto">>
+        <<"timestamp_format">> => <<"auto">>,
+        <<"payload_encode">> => <<"text">>
     },
     ExpectLog1 = #{
         <<"console">> =>
@@ -86,6 +87,7 @@ t_log_conf(_Conf) ->
                 <<"enable">> => true,
                 <<"formatter">> => <<"text">>,
                 <<"level">> => <<"debug">>,
+                <<"payload_encode">> => <<"text">>,
                 <<"time_offset">> => <<"system">>,
                 <<"timestamp_format">> => <<"auto">>
             },

+ 9 - 4
apps/emqx_enterprise/test/emqx_enterprise_schema_SUITE.erl

@@ -79,7 +79,8 @@ t_audit_log_conf(_Config) ->
         <<"rotation_size">> => <<"50MB">>,
         <<"time_offset">> => <<"system">>,
         <<"path">> => <<"log/emqx.log">>,
-        <<"timestamp_format">> => <<"auto">>
+        <<"timestamp_format">> => <<"auto">>,
+        <<"payload_encode">> => <<"text">>
     },
     ExpectLog1 = #{
         <<"console">> =>
@@ -88,10 +89,13 @@ t_audit_log_conf(_Config) ->
                 <<"formatter">> => <<"text">>,
                 <<"level">> => <<"warning">>,
                 <<"time_offset">> => <<"system">>,
-                <<"timestamp_format">> => <<"auto">>
+                <<"timestamp_format">> => <<"auto">>,
+                <<"payload_encode">> => <<"text">>
             },
         <<"file">> =>
-            #{<<"default">> => FileExpect},
+            #{
+                <<"default">> => FileExpect
+            },
         <<"audit">> =>
             #{
                 <<"enable">> => false,
@@ -102,7 +106,8 @@ t_audit_log_conf(_Config) ->
                 <<"rotation_count">> => 10,
                 <<"rotation_size">> => <<"50MB">>,
                 <<"time_offset">> => <<"system">>,
-                <<"timestamp_format">> => <<"auto">>
+                <<"timestamp_format">> => <<"auto">>,
+                <<"payload_encode">> => <<"text">>
             }
     },
     %% The default value of throttling.msgs can be frequently updated,