fix: check if trace is enabled when the file is not found

This commit is contained in:
zhongwencool 2022-08-08 11:59:26 +08:00
parent 683bec16a3
commit 2740c80b20
1 changed files with 7 additions and 0 deletions

View File

@ -145,6 +145,8 @@ stream_log_file(#{name := Name}, Params) ->
{eof, Size} ->
Meta = #{<<"position">> => Size, <<"bytes">> => Bytes},
{ok, #{meta => Meta, items => <<"">>}};
{error, trace_disabled} ->
{error, io_lib:format("trace_disable_on_~s", [Node0])};
{error, Reason} ->
logger:log(error, "read_file_failed ~p", [{Node, Name, Reason, Position, Bytes}]),
{error, Reason};
@ -194,6 +196,11 @@ read_file(Path, Offset, Bytes) ->
after
file:close(IoDevice)
end;
{error, enoent} ->
case emqx_trace:is_enable() of
false -> {error, trace_disabled};
true -> {error, enoent}
end;
{error, Reason} -> {error, Reason}
end.