fix: audit log format
This commit is contained in:
parent
3798060543
commit
8965aa2a21
|
@ -95,7 +95,7 @@ to_audit(#{from := erlang_console, function := F, args := Args}) ->
|
|||
http_method = <<"">>,
|
||||
http_request = <<"">>,
|
||||
duration_ms = 0,
|
||||
args = iolist_to_binary(io_lib:format("~p: ~p~n", [F, Args]))
|
||||
args = iolist_to_binary(io_lib:format("~p: ~ts", [F, Args]))
|
||||
}.
|
||||
|
||||
log(_Level, undefined, _Handler) ->
|
||||
|
@ -141,7 +141,7 @@ handle_continue(setup, State) ->
|
|||
NewState = State#{role => mria_rlog:role()},
|
||||
?AUDIT(alert, #{
|
||||
cmd => emqx,
|
||||
args => ["start"],
|
||||
args => [<<"start">>],
|
||||
version => emqx_release:version(),
|
||||
from => cli,
|
||||
duration_ms => 0
|
||||
|
|
|
@ -1520,7 +1520,8 @@ ensure_file_handlers(Conf, _Opts) ->
|
|||
|
||||
convert_rotation(undefined, _Opts) -> undefined;
|
||||
convert_rotation(#{} = Rotation, _Opts) -> maps:get(<<"count">>, Rotation, 10);
|
||||
convert_rotation(Count, _Opts) when is_integer(Count) -> Count.
|
||||
convert_rotation(Count, _Opts) when is_integer(Count) -> Count;
|
||||
convert_rotation(Count, _Opts) -> throw({"bad_rotation", Count}).
|
||||
|
||||
ensure_unicode_path(undefined, _) ->
|
||||
undefined;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{application, emqx_ctl, [
|
||||
{description, "Backend for emqx_ctl script"},
|
||||
{vsn, "0.1.5"},
|
||||
{vsn, "0.1.6"},
|
||||
{registered, []},
|
||||
{mod, {emqx_ctl_app, []}},
|
||||
{applications, [
|
||||
|
|
|
@ -339,11 +339,25 @@ audit_log(Level, From, Log) ->
|
|||
try
|
||||
apply(Mod, Fun, [Level, From, normalize_audit_log_args(Log)])
|
||||
catch
|
||||
_:{aborted, {no_exists, emqx_audit}} ->
|
||||
case Log of
|
||||
#{cmd := cluster, args := ["leave"]} ->
|
||||
ok;
|
||||
_ ->
|
||||
?LOG_ERROR(#{
|
||||
msg => "ctl_command_crashed",
|
||||
reason => "emqx_audit table not found",
|
||||
log => normalize_audit_log_args(Log),
|
||||
from => From
|
||||
})
|
||||
end;
|
||||
_:Reason:Stacktrace ->
|
||||
?LOG_ERROR(#{
|
||||
msg => "ctl_command_crashed",
|
||||
stacktrace => Stacktrace,
|
||||
reason => Reason
|
||||
reason => Reason,
|
||||
log => normalize_audit_log_args(Log),
|
||||
from => From
|
||||
})
|
||||
end
|
||||
end.
|
||||
|
|
|
@ -46,6 +46,7 @@ log_meta(Meta, Req) ->
|
|||
true ->
|
||||
undefined;
|
||||
false ->
|
||||
Code = maps:get(code, Meta),
|
||||
Meta1 = #{
|
||||
time => logger:timestamp(),
|
||||
from => from(Meta),
|
||||
|
@ -56,8 +57,8 @@ log_meta(Meta, Req) ->
|
|||
%% method for http filter api.
|
||||
http_method => Method,
|
||||
http_request => http_request(Meta),
|
||||
http_status_code => maps:get(code, Meta),
|
||||
operation_result => operation_result(Meta),
|
||||
http_status_code => Code,
|
||||
operation_result => operation_result(Code, Meta),
|
||||
node => node()
|
||||
},
|
||||
Meta2 = maps:without([req_start, req_end, method, headers, body, bindings, code], Meta),
|
||||
|
@ -105,8 +106,9 @@ operation_type(Meta) ->
|
|||
http_request(Meta) ->
|
||||
maps:with([method, headers, bindings, body], Meta).
|
||||
|
||||
operation_result(#{failure := _}) -> failure;
|
||||
operation_result(_) -> success.
|
||||
operation_result(Code, _) when Code >= 300 -> failure;
|
||||
operation_result(_, #{failure := _}) -> failure;
|
||||
operation_result(_, _) -> success.
|
||||
|
||||
level(get, _Code) -> debug;
|
||||
level(_, Code) when Code >= 200 andalso Code < 300 -> info;
|
||||
|
|
Loading…
Reference in New Issue