chore(audit): add from field
This commit is contained in:
parent
ece7d5b52a
commit
dd9938114c
|
@ -61,7 +61,9 @@
|
||||||
)
|
)
|
||||||
end).
|
end).
|
||||||
|
|
||||||
-define(AUDIT(_Level_, _Msg_, _Meta_), begin
|
-define(AUDIT(_Level_, _From_, _Meta_), ?AUDIT(_Level_, _From_, undefined, _Meta_)).
|
||||||
|
|
||||||
|
-define(AUDIT(_Level_, _From_, _Msg_, _Meta_), begin
|
||||||
case emqx_config:get([log, audit], #{enable => false}) of
|
case emqx_config:get([log, audit], #{enable => false}) of
|
||||||
#{enable := false} ->
|
#{enable := false} ->
|
||||||
ok;
|
ok;
|
||||||
|
@ -72,7 +74,7 @@ end).
|
||||||
_Level_,
|
_Level_,
|
||||||
[{emqx_audit, fun(L, _) -> L end, undefined, undefined}],
|
[{emqx_audit, fun(L, _) -> L end, undefined, undefined}],
|
||||||
{report, _Msg_},
|
{report, _Msg_},
|
||||||
_Meta_
|
_Meta_#{from => _From_}
|
||||||
);
|
);
|
||||||
gt ->
|
gt ->
|
||||||
ok
|
ok
|
||||||
|
|
|
@ -87,8 +87,13 @@ log(List, Msg, Meta) ->
|
||||||
log(debug, List, Msg, Meta).
|
log(debug, List, Msg, Meta).
|
||||||
|
|
||||||
log(Level, List, Msg, Meta) ->
|
log(Level, List, Msg, Meta) ->
|
||||||
Log = #{level => Level, meta => enrich_meta(Meta), msg => Msg},
|
Log = #{level => Level, meta => enrich_meta(Meta)},
|
||||||
log_filter(List, Log).
|
Log1 =
|
||||||
|
case Msg of
|
||||||
|
undefined -> Log;
|
||||||
|
_ -> maps:put(msg, Msg, Log)
|
||||||
|
end,
|
||||||
|
log_filter(List, Log1).
|
||||||
|
|
||||||
enrich_meta(Meta) ->
|
enrich_meta(Meta) ->
|
||||||
case logger:get_process_metadata() of
|
case logger:get_process_metadata() of
|
||||||
|
|
|
@ -145,7 +145,7 @@ run_command(Cmd, Args) when is_atom(Cmd) ->
|
||||||
|
|
||||||
audit_log(
|
audit_log(
|
||||||
audit_level(Result, Duration),
|
audit_level(Result, Duration),
|
||||||
"from_cli",
|
cli,
|
||||||
#{duration_ms => Duration, cmd => Cmd, args => Args, node => node()}
|
#{duration_ms => Duration, cmd => Cmd, args => Args, node => node()}
|
||||||
),
|
),
|
||||||
Result.
|
Result.
|
||||||
|
|
|
@ -30,7 +30,7 @@ log(Meta0) ->
|
||||||
Meta = emqx_utils:redact(Meta2),
|
Meta = emqx_utils:redact(Meta2),
|
||||||
?AUDIT(
|
?AUDIT(
|
||||||
Level,
|
Level,
|
||||||
"from_api",
|
rest_api,
|
||||||
Meta#{
|
Meta#{
|
||||||
from => from(maps:get(auth_type, Meta0, "")),
|
from => from(maps:get(auth_type, Meta0, "")),
|
||||||
username => binary_to_list(Username),
|
username => binary_to_list(Username),
|
||||||
|
|
|
@ -47,7 +47,7 @@ post_boot() ->
|
||||||
ok = ensure_apps_started(),
|
ok = ensure_apps_started(),
|
||||||
ok = print_vsn(),
|
ok = print_vsn(),
|
||||||
ok = start_autocluster(),
|
ok = start_autocluster(),
|
||||||
?AUDIT(alert, "from_cli", #{time => logger:timestamp(), event => "emqx_start"}),
|
?AUDIT(alert, cli, #{time => logger:timestamp(), event => "emqx_start"}),
|
||||||
ignore.
|
ignore.
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
|
|
|
@ -67,8 +67,8 @@ graceful() ->
|
||||||
|
|
||||||
%% @doc Shutdown the Erlang VM and wait indefinitely.
|
%% @doc Shutdown the Erlang VM and wait indefinitely.
|
||||||
graceful_wait() ->
|
graceful_wait() ->
|
||||||
?AUDIT(alert, "from_cli", #{
|
?AUDIT(alert, cli, run_emqx_stop_to_grace_shutdown, #{
|
||||||
time => logger:timestamp(), msg => "run_emqx_stop_to_grace_shutdown"
|
time => logger:timestamp()
|
||||||
}),
|
}),
|
||||||
ok = graceful(),
|
ok = graceful(),
|
||||||
exit_loop().
|
exit_loop().
|
||||||
|
|
|
@ -112,7 +112,7 @@ max_heap_size_warning(MF, Args) ->
|
||||||
log(_, {?MODULE, prompt_func}, [[{history, _}]]) ->
|
log(_, {?MODULE, prompt_func}, [[{history, _}]]) ->
|
||||||
ok;
|
ok;
|
||||||
log(IsAllow, MF, Args) ->
|
log(IsAllow, MF, Args) ->
|
||||||
?AUDIT(warning, "from_remote_console", #{
|
?AUDIT(warning, remote_console, #{
|
||||||
time => logger:timestamp(),
|
time => logger:timestamp(),
|
||||||
function => MF,
|
function => MF,
|
||||||
args => pp_args(Args),
|
args => pp_args(Args),
|
||||||
|
|
Loading…
Reference in New Issue