From 416c9c9185918a3554a712401b852e227832ce43 Mon Sep 17 00:00:00 2001 From: lijie <1713699517@qq.com> Date: Wed, 1 Feb 2023 15:52:45 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E9=80=82=E9=85=8DeFmt=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/lgDef.hrl | 2 +- src/crashLog/lgCrashLog.erl | 16 ++++++++-------- src/eLog.erl | 14 +++++++------- src/errLogger/lgErrLoggerH.erl | 26 +++++++++++++------------- src/formatter/lgFmtTer.erl | 12 ++++++------ 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/include/lgDef.hrl b/include/lgDef.hrl index 52ed428..1db7166 100644 --- a/include/lgDef.hrl +++ b/include/lgDef.hrl @@ -125,7 +125,7 @@ -define(LgShouldLog(Level), ?eLogCfg:get(?LgDefSink) band Level =/= 0). -define(LgNotify(Level, Pid, Format, Args), - gen_emm:info_notify(?LgDefSink, {mWriteLog, #lgMsg{severity = Level, pid = Pid, node = node(), module = ?MODULE, function = ?FUNCTION_NAME, line = ?LINE, metadata = [], datetime = lgUtil:msToBinStr(), timestamp = lgTime:nowMs(), message = eFmt:formatBin(Format, Args), destinations = []}})). + gen_emm:info_notify(?LgDefSink, {mWriteLog, #lgMsg{severity = Level, pid = Pid, node = node(), module = ?MODULE, function = ?FUNCTION_NAME, line = ?LINE, metadata = [], datetime = lgUtil:msToBinStr(), timestamp = lgTime:nowMs(), message = eFmt:format(Format, Args), destinations = []}})). %%仅供内部使用仅内部非阻塞日志记录调用,当我们仍在启动大型啤酒时尝试进行日志记录(通常为错误)时,会有一些特殊处理。 -define(INT_LOG(Level, Format, Args), diff --git a/src/crashLog/lgCrashLog.erl b/src/crashLog/lgCrashLog.erl index 78bb147..59e733c 100644 --- a/src/crashLog/lgCrashLog.erl +++ b/src/crashLog/lgCrashLog.erl @@ -141,26 +141,26 @@ saslLimitedStr(supervisor_report, Report, FmtMaxBytes) -> Reason = lgUtil:sup_get(reason, Report), Offender = lgUtil:sup_get(offender, Report), FmtString = <<" Supervisor: ~p~n Context: ~p~n Reason: ~s~n Offender: ~s~n">>, - ReasonStr = eFmt:formatBin(<<"~p">>, [Reason], [{charsLimit, FmtMaxBytes}]), - OffenderStr = eFmt:formatBin(<<"~p">>, [Offender], [{charsLimit, FmtMaxBytes}]), + ReasonStr = eFmt:format(<<"~p">>, [Reason], [{charsLimit, FmtMaxBytes}]), + OffenderStr = eFmt:format(<<"~p">>, [Offender], [{charsLimit, FmtMaxBytes}]), eFmt:format(FmtString, [Name, Context, ReasonStr, OffenderStr]); saslLimitedStr(progress, Report, FmtMaxBytes) -> [ begin - BinStr = eFmt:formatBin(<<"~p">>, [Data], [{charsLimit, FmtMaxBytes}]), - eFmt:formatBin(<<" ~16w: ~s~n">>, [Tag, BinStr]) + BinStr = eFmt:format(<<"~p">>, [Data], [{charsLimit, FmtMaxBytes}]), + eFmt:format(<<" ~16w: ~s~n">>, [Tag, BinStr]) end || {Tag, Data} <- Report ]; saslLimitedStr(crash_report, Report, FmtMaxBytes) -> - eFmt:formatBin(<<"~p">>, [Report], [{charsLimit, FmtMaxBytes}]). + eFmt:format(<<"~p">>, [Report], [{charsLimit, FmtMaxBytes}]). writeLog(Event, #state{fileName = FileName, fd = FD, inode = Inode, cTime = CTime, flap = Flap, maxFmtSize = FmtMaxBytes, maxFileSize = RotSize, rotator = Rotator} = State) -> {ReportStr, Pid, MsgStr, _ErrorP} = case Event of {error, _GL, {Pid1, Fmt, Args}} -> - {<<"ERROR REPORT">>, Pid1, eFmt:formatBin(Fmt, Args, [{charsLimit, FmtMaxBytes}]), true}; + {<<"ERROR REPORT">>, Pid1, eFmt:format(Fmt, Args, [{charsLimit, FmtMaxBytes}]), true}; {error_report, _GL, {Pid1, std_error, Rep}} -> - {<<"ERROR REPORT">>, Pid1, eFmt:formatBin(<<"~p">>, [Rep], [{charsLimit, FmtMaxBytes}]), true}; + {<<"ERROR REPORT">>, Pid1, eFmt:format(<<"~p">>, [Rep], [{charsLimit, FmtMaxBytes}]), true}; {error_report, _GL, Other} -> perhapsSaslReport(error_report, Other, FmtMaxBytes); _ -> @@ -180,7 +180,7 @@ writeLog(Event, #state{fileName = FileName, fd = FD, inode = Inode, cTime = CTim TimeBinStr = lgUtil:msToBinStr(), Time = [TimeBinStr, <<" =">>, ReportStr, <<"====\n\t\t">>], NodeSuffix = otherNodeSuffix(Pid), - Msg = eFmt:formatBin(<<"~s~s~s~n">>, [Time, MsgStr, NodeSuffix]), + Msg = eFmt:format(<<"~s~s~s~n">>, [Time, MsgStr, NodeSuffix]), case file:write(NewFD, unicode:characters_to_binary(Msg)) of {error, Reason} when Flap == false -> ?INT_LOG(?llvError, <<"Failed to write log message to file ~ts: ~s">>, [FileName, file:format_error(Reason)]), diff --git a/src/eLog.erl b/src/eLog.erl index 6a51cae..5ba2914 100644 --- a/src/eLog.erl +++ b/src/eLog.erl @@ -234,17 +234,17 @@ parseStack(Stacktrace) -> begin case Location of [] -> - <<" ", (atom_to_binary(Mod, utf8))/binary, ":", (atom_to_binary(Func, utf8))/binary, "(", (eFmt:formatBin(<<"~w">>, [Arity]))/binary, ")\n">>; + <<" ", (atom_to_binary(Mod, utf8))/binary, ":", (atom_to_binary(Func, utf8))/binary, "(", (eFmt:format(<<"~w">>, [Arity]))/binary, ")\n">>; [{file, File}, {line, Line}] -> <<" ", (atom_to_binary(Mod, utf8))/binary, ":", (atom_to_binary(Func, utf8))/binary, "/", (integer_to_binary(Arity))/binary, "(", (unicode:characters_to_binary(File))/binary, ":", (integer_to_binary(Line))/binary, ")\n">>; _ -> - <<" ", (atom_to_binary(Mod, utf8))/binary, ":", (atom_to_binary(Func, utf8))/binary, "(", (eFmt:formatBin(<<"~w">>, [Arity]))/binary, ")", (eFmt:formatBin(<<"~w">>, [Location]))/binary, "\n">> + <<" ", (atom_to_binary(Mod, utf8))/binary, ":", (atom_to_binary(Func, utf8))/binary, "(", (eFmt:format(<<"~w">>, [Arity]))/binary, ")", (eFmt:format(<<"~w">>, [Location]))/binary, "\n">> end end || {Mod, Func, Arity, Location} <- Stacktrace >>. parseStack(Class, Reason, Stacktrace) -> - eFmt:formatBin(<<"~n Class:~p~n Reason:~p~n Stacktrace:~s">>, [Class, Reason, parseStack(Stacktrace)]). + eFmt:format(<<"~n Class:~p~n Reason:~p~n Stacktrace:~s">>, [Class, Reason, parseStack(Stacktrace)]). trace(BkdMod, Filter) -> trace(BkdMod, Filter, debug). @@ -493,16 +493,16 @@ add_trace_to_loglevel_config(Trace, Sink) -> %% arguments. The caller is NOT crashed. unsafeFormat(Fmt, Args) -> - try eFmt:formatBin(Fmt, Args) + try eFmt:format(Fmt, Args) catch - _:_ -> eFmt:formatBin(<<"FORMAT ERROR SAFE: ~p ~p">>, [Fmt, Args]) + _:_ -> eFmt:format(<<"FORMAT ERROR SAFE: ~p ~p">>, [Fmt, Args]) end. safeFormat(Fmt, Args, Limit) -> - try eFmt:formatBin(Fmt, Args, Limit) + try eFmt:format(Fmt, Args, Limit) catch _:_ -> - eFmt:formatBin(<<"FORMAT ERROR UNSAFE: ~p ~p">>, [Fmt, Args], Limit) + eFmt:format(<<"FORMAT ERROR UNSAFE: ~p ~p">>, [Fmt, Args], Limit) end. %% @private Print the format string `Fmt' with `Args' without a size limit. diff --git a/src/errLogger/lgErrLoggerH.erl b/src/errLogger/lgErrLoggerH.erl index 5a420a8..a6e0e38 100644 --- a/src/errLogger/lgErrLoggerH.erl +++ b/src/errLogger/lgErrLoggerH.erl @@ -394,13 +394,13 @@ formatCrashReport(Report, Neighbours) -> {Class, Reason, Trace} = get_value(error_info, Report), {Md, ReasonStr} = formatReasonMd({Reason, Trace}), Type = ?IIF(Class == exit, <<"exited">>, <<"crashed">>), - {Md0 ++ Md, eFmt:formatBin(<<"Process ~w with ~w neighbours ~s with reason: ~s">>, [Name, length(Neighbours), Type, ReasonStr])}. + {Md0 ++ Md, eFmt:format(<<"Process ~w with ~w neighbours ~s with reason: ~s">>, [Name, length(Neighbours), Type, ReasonStr])}. formatOffender(Off) -> case get_value(mfargs, Off) of undefined -> %% supervisor_bridge - eFmt:formatBin(<<"at module ~w at ~w">>, [get_value(mod, Off), get_value(pid, Off)]); + eFmt:format(<<"at module ~w at ~w">>, [get_value(mod, Off), get_value(pid, Off)]); MFArgs -> %% regular supervisor {_, MFA} = formatMfaMd(MFArgs), @@ -414,7 +414,7 @@ formatOffender(Off) -> Id -> Id end, - eFmt:formatBin(<<"Name ~w at module ~s at ~w">>, [Name, MFA, get_value(pid, Off)]) + eFmt:format(<<"Name ~w at module ~s at ~w">>, [Name, MFA, get_value(pid, Off)]) end. %% backwards compatability shim @@ -481,7 +481,7 @@ formatReasonMd({system_limit, [{M, F, _} | _] = Trace}) -> {ets, new} -> <<"maximum number of ETS tables exceeded">>; _ -> - eFmt:formatBin(<<"~p">>, [Trace], [{charsLimit, 500}]) + eFmt:format(<<"~p">>, [Trace], [{charsLimit, 500}]) end, {[{reason, system_limit}], <<"system limit: ", Limit/binary>>}; formatReasonMd({badarg, [MFA, MFA2 | _]}) -> @@ -505,7 +505,7 @@ formatReasonMd({{badarg, Stack}, _}) -> formatReasonMd({{badarity, {Fun, Args}}, [MFA | _]}) -> {arity, Arity} = lists:keyfind(arity, 1, erlang:fun_info(Fun)), {Md, Formatted} = formatMfaMd(MFA), - {[{reason, badarity} | Md], eFmt:formatBin(<<"fun called with wrong arity of ~w instead of ~w in ~s">>, [length(Args), Arity, Formatted])}; + {[{reason, badarity} | Md], eFmt:format(<<"fun called with wrong arity of ~w instead of ~w in ~s">>, [length(Args), Arity, Formatted])}; formatReasonMd({noproc, MFA}) -> {Md, Formatted} = formatMfaMd(MFA), {[{reason, noproc} | Md], <<"no such process or port in call to ", Formatted/binary>>}; @@ -522,7 +522,7 @@ formatReasonMd({Reason, [{M, F, A, Props} | _]}) when is_atom(M), is_atom(F), is {_, Formatted2} = formatMfaMd({M, F, A, Props}), {Md, <>}; formatReasonMd(Reason) -> - {[], eFmt:formatBin(<<"~p">>, [Reason], [{charsLimit, 500}])}. + {[], eFmt:format(<<"~p">>, [Reason], [{charsLimit, 500}])}. %% backwards compatability shim formatMfa(MFA) -> @@ -531,9 +531,9 @@ formatMfa(MFA) -> -spec formatMfaMd(any()) -> {[{atom(), any()}], list()}. formatMfaMd({M, F, A}) when is_list(A) -> ArgsStr = formatArgs(A, <<>>), - {[{module, M}, {function, F}], eFmt:formatBin(<<"~w:~w(", ArgsStr/binary, ")">>, [M, F])}; + {[{module, M}, {function, F}], eFmt:format(<<"~w:~w(", ArgsStr/binary, ")">>, [M, F])}; formatMfaMd({M, F, A}) when is_integer(A) -> - {[{module, M}, {function, F}], eFmt:formatBin(<<"~w:~w/~w">>, [M, F, A])}; + {[{module, M}, {function, F}], eFmt:format(<<"~w:~w/~w">>, [M, F, A])}; formatMfaMd({M, F, A, Props}) when is_list(Props) -> case get_value(line, Props) of undefined -> @@ -551,22 +551,22 @@ formatMfaMd([{M, F, A, Props} | _]) when is_list(Props) -> %% to print a lower one, but it is hard to programatically decide. formatMfaMd({M, F, A, Props}); formatMfaMd(Other) -> - {[], eFmt:formatBin(<<"~w">>, [Other])}. + {[], eFmt:format(<<"~w">>, [Other])}. formatArgs([], ArgsAcc) -> ArgsAcc; formatArgs([H], ArgsAcc) -> - Str = eFmt:formatBin(<<"~p">>, [H], [{charsLimit, 100}]), + Str = eFmt:format(<<"~p">>, [H], [{charsLimit, 100}]), <>; formatArgs([H | T], ArgsAcc) -> - Str = eFmt:formatBin(<<"~p">>, [H], [{charsLimit, 100}]), + Str = eFmt:format(<<"~p">>, [H], [{charsLimit, 100}]), formatArgs(T, <>). formatVal(Val) -> - eFmt:formatBin(<<"~p">>, [Val], [{charsLimit, 500}]). + eFmt:format(<<"~p">>, [Val], [{charsLimit, 500}]). printSillyList(L) -> - eFmt:formatBin(<<"~p">>, [L], [{charsLimit, ?LgDefTruncation}]). + eFmt:format(<<"~p">>, [L], [{charsLimit, ?LgDefTruncation}]). %% @doc Faster than proplists, but with the same API as long as you don't need to %% handle bare atom keys diff --git a/src/formatter/lgFmtTer.erl b/src/formatter/lgFmtTer.erl index bf67612..92aa927 100644 --- a/src/formatter/lgFmtTer.erl +++ b/src/formatter/lgFmtTer.erl @@ -145,11 +145,11 @@ outColor(Colors, LgMsg) -> makeStr(A) when is_atom(A) -> atom_to_binary(A); makeStr(P) when is_pid(P) -> list_to_binary(pid_to_list(P)); makeStr(B) when is_binary(B) -> B; -makeStr(Other) -> eFmt:formatBin(<<"~p">>, [Other]). +makeStr(Other) -> eFmt:format(<<"~p">>, [Other]). makeList(A) when is_atom(A) -> atom_to_list(A); makeList(P) when is_pid(P) -> pid_to_list(P); -makeList(Other) -> binary_to_list(eFmt:formatBin(<<"~p">>, [Other])). +makeList(Other) -> binary_to_list(eFmt:format(<<"~p">>, [Other])). makeStr(A, W) when is_integer(W) -> makeStr(left, makeList(A), W); makeStr(A, {Align, W}) when is_integer(W) -> @@ -229,16 +229,16 @@ sevSeverity(?llvNone) -> <<"[o]">>. mdJoin([], _FieldSep, BinAcc) -> BinAcc; mdJoin([{_K, V}], _FieldSep, BinAcc) -> - <>, [V]))/binary>>; + <>, [V]))/binary>>; mdJoin([{_K, V} | Left], FieldSep, BinAcc) -> - mdJoin(Left, FieldSep, <>, [V]))/binary, FieldSep/binary>>). + mdJoin(Left, FieldSep, <>, [V]))/binary, FieldSep/binary>>). mdJoin([], _IntSep, _FieldSep, BinAcc) -> BinAcc; mdJoin([{K, V}], IntSep, _FieldSep, BinAcc) -> - <>, [K, IntSep, V]))/binary>>; + <>, [K, IntSep, V]))/binary>>; mdJoin([{K, V} | Left], IntSep, FieldSep, BinAcc) -> - mdJoin(Left, FieldSep, <>, [K, IntSep, V]))/binary, FieldSep/binary>>). + mdJoin(Left, FieldSep, <>, [K, IntSep, V]))/binary, FieldSep/binary>>).