Преглед изворни кода

ft: 适配eFmt优化

master
lijie пре 2 година
родитељ
комит
416c9c9185
5 измењених фајлова са 35 додато и 35 уклоњено
  1. +1
    -1
      include/lgDef.hrl
  2. +8
    -8
      src/crashLog/lgCrashLog.erl
  3. +7
    -7
      src/eLog.erl
  4. +13
    -13
      src/errLogger/lgErrLoggerH.erl
  5. +6
    -6
      src/formatter/lgFmtTer.erl

+ 1
- 1
include/lgDef.hrl Прегледај датотеку

@ -125,7 +125,7 @@
-define(LgShouldLog(Level), ?eLogCfg:get(?LgDefSink) band Level =/= 0). -define(LgShouldLog(Level), ?eLogCfg:get(?LgDefSink) band Level =/= 0).
-define(LgNotify(Level, Pid, Format, Args), -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), -define(INT_LOG(Level, Format, Args),

+ 8
- 8
src/crashLog/lgCrashLog.erl Прегледај датотеку

@ -141,26 +141,26 @@ saslLimitedStr(supervisor_report, Report, FmtMaxBytes) ->
Reason = lgUtil:sup_get(reason, Report), Reason = lgUtil:sup_get(reason, Report),
Offender = lgUtil:sup_get(offender, Report), Offender = lgUtil:sup_get(offender, Report),
FmtString = <<" Supervisor: ~p~n Context: ~p~n Reason: ~s~n Offender: ~s~n">>, 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]); eFmt:format(FmtString, [Name, Context, ReasonStr, OffenderStr]);
saslLimitedStr(progress, Report, FmtMaxBytes) -> saslLimitedStr(progress, Report, FmtMaxBytes) ->
[ [
begin 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 end || {Tag, Data} <- Report
]; ];
saslLimitedStr(crash_report, Report, FmtMaxBytes) -> 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) -> writeLog(Event, #state{fileName = FileName, fd = FD, inode = Inode, cTime = CTime, flap = Flap, maxFmtSize = FmtMaxBytes, maxFileSize = RotSize, rotator = Rotator} = State) ->
{ReportStr, Pid, MsgStr, _ErrorP} = {ReportStr, Pid, MsgStr, _ErrorP} =
case Event of case Event of
{error, _GL, {Pid1, Fmt, Args}} -> {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, _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} -> {error_report, _GL, Other} ->
perhapsSaslReport(error_report, Other, FmtMaxBytes); perhapsSaslReport(error_report, Other, FmtMaxBytes);
_ -> _ ->
@ -180,7 +180,7 @@ writeLog(Event, #state{fileName = FileName, fd = FD, inode = Inode, cTime = CTim
TimeBinStr = lgUtil:msToBinStr(), TimeBinStr = lgUtil:msToBinStr(),
Time = [TimeBinStr, <<" =">>, ReportStr, <<"====\n\t\t">>], Time = [TimeBinStr, <<" =">>, ReportStr, <<"====\n\t\t">>],
NodeSuffix = otherNodeSuffix(Pid), 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 case file:write(NewFD, unicode:characters_to_binary(Msg)) of
{error, Reason} when Flap == false -> {error, Reason} when Flap == false ->
?INT_LOG(?llvError, <<"Failed to write log message to file ~ts: ~s">>, [FileName, file:format_error(Reason)]), ?INT_LOG(?llvError, <<"Failed to write log message to file ~ts: ~s">>, [FileName, file:format_error(Reason)]),

+ 7
- 7
src/eLog.erl Прегледај датотеку

@ -234,17 +234,17 @@ parseStack(Stacktrace) ->
begin begin
case Location of 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}] -> [{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, "/", (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
end || {Mod, Func, Arity, Location} <- Stacktrace end || {Mod, Func, Arity, Location} <- Stacktrace
>>. >>.
parseStack(Class, Reason, 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) ->
trace(BkdMod, Filter, debug). trace(BkdMod, Filter, debug).
@ -493,16 +493,16 @@ add_trace_to_loglevel_config(Trace, Sink) ->
%% arguments. The caller is NOT crashed. %% arguments. The caller is NOT crashed.
unsafeFormat(Fmt, Args) -> unsafeFormat(Fmt, Args) ->
try eFmt:formatBin(Fmt, Args)
try eFmt:format(Fmt, Args)
catch catch
_:_ -> eFmt:formatBin(<<"FORMAT ERROR SAFE: ~p ~p">>, [Fmt, Args])
_:_ -> eFmt:format(<<"FORMAT ERROR SAFE: ~p ~p">>, [Fmt, Args])
end. end.
safeFormat(Fmt, Args, Limit) -> safeFormat(Fmt, Args, Limit) ->
try eFmt:formatBin(Fmt, Args, Limit)
try eFmt:format(Fmt, Args, Limit)
catch catch
_:_ -> _:_ ->
eFmt:formatBin(<<"FORMAT ERROR UNSAFE: ~p ~p">>, [Fmt, Args], Limit)
eFmt:format(<<"FORMAT ERROR UNSAFE: ~p ~p">>, [Fmt, Args], Limit)
end. end.
%% @private Print the format string `Fmt' with `Args' without a size limit. %% @private Print the format string `Fmt' with `Args' without a size limit.

+ 13
- 13
src/errLogger/lgErrLoggerH.erl Прегледај датотеку

@ -394,13 +394,13 @@ formatCrashReport(Report, Neighbours) ->
{Class, Reason, Trace} = get_value(error_info, Report), {Class, Reason, Trace} = get_value(error_info, Report),
{Md, ReasonStr} = formatReasonMd({Reason, Trace}), {Md, ReasonStr} = formatReasonMd({Reason, Trace}),
Type = ?IIF(Class == exit, <<"exited">>, <<"crashed">>), 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) -> formatOffender(Off) ->
case get_value(mfargs, Off) of case get_value(mfargs, Off) of
undefined -> undefined ->
%% supervisor_bridge %% 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 -> MFArgs ->
%% regular supervisor %% regular supervisor
{_, MFA} = formatMfaMd(MFArgs), {_, MFA} = formatMfaMd(MFArgs),
@ -414,7 +414,7 @@ formatOffender(Off) ->
Id -> Id ->
Id Id
end, 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. end.
%% backwards compatability shim %% backwards compatability shim
@ -481,7 +481,7 @@ formatReasonMd({system_limit, [{M, F, _} | _] = Trace}) ->
{ets, new} -> {ets, new} ->
<<"maximum number of ETS tables exceeded">>; <<"maximum number of ETS tables exceeded">>;
_ -> _ ->
eFmt:formatBin(<<"~p">>, [Trace], [{charsLimit, 500}])
eFmt:format(<<"~p">>, [Trace], [{charsLimit, 500}])
end, end,
{[{reason, system_limit}], <<"system limit: ", Limit/binary>>}; {[{reason, system_limit}], <<"system limit: ", Limit/binary>>};
formatReasonMd({badarg, [MFA, MFA2 | _]}) -> formatReasonMd({badarg, [MFA, MFA2 | _]}) ->
@ -505,7 +505,7 @@ formatReasonMd({{badarg, Stack}, _}) ->
formatReasonMd({{badarity, {Fun, Args}}, [MFA | _]}) -> formatReasonMd({{badarity, {Fun, Args}}, [MFA | _]}) ->
{arity, Arity} = lists:keyfind(arity, 1, erlang:fun_info(Fun)), {arity, Arity} = lists:keyfind(arity, 1, erlang:fun_info(Fun)),
{Md, Formatted} = formatMfaMd(MFA), {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}) -> formatReasonMd({noproc, MFA}) ->
{Md, Formatted} = formatMfaMd(MFA), {Md, Formatted} = formatMfaMd(MFA),
{[{reason, noproc} | Md], <<"no such process or port in call to ", Formatted/binary>>}; {[{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}), {_, Formatted2} = formatMfaMd({M, F, A, Props}),
{Md, <<Formatted/binary, " in ", Formatted2/binary>>}; {Md, <<Formatted/binary, " in ", Formatted2/binary>>};
formatReasonMd(Reason) -> formatReasonMd(Reason) ->
{[], eFmt:formatBin(<<"~p">>, [Reason], [{charsLimit, 500}])}.
{[], eFmt:format(<<"~p">>, [Reason], [{charsLimit, 500}])}.
%% backwards compatability shim %% backwards compatability shim
formatMfa(MFA) -> formatMfa(MFA) ->
@ -531,9 +531,9 @@ formatMfa(MFA) ->
-spec formatMfaMd(any()) -> {[{atom(), any()}], list()}. -spec formatMfaMd(any()) -> {[{atom(), any()}], list()}.
formatMfaMd({M, F, A}) when is_list(A) -> formatMfaMd({M, F, A}) when is_list(A) ->
ArgsStr = formatArgs(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) -> 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) -> formatMfaMd({M, F, A, Props}) when is_list(Props) ->
case get_value(line, Props) of case get_value(line, Props) of
undefined -> 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. %% to print a lower one, but it is hard to programatically decide.
formatMfaMd({M, F, A, Props}); formatMfaMd({M, F, A, Props});
formatMfaMd(Other) -> formatMfaMd(Other) ->
{[], eFmt:formatBin(<<"~w">>, [Other])}.
{[], eFmt:format(<<"~w">>, [Other])}.
formatArgs([], ArgsAcc) -> formatArgs([], ArgsAcc) ->
ArgsAcc; ArgsAcc;
formatArgs([H], ArgsAcc) -> formatArgs([H], ArgsAcc) ->
Str = eFmt:formatBin(<<"~p">>, [H], [{charsLimit, 100}]),
Str = eFmt:format(<<"~p">>, [H], [{charsLimit, 100}]),
<<ArgsAcc/binary, Str/binary>>; <<ArgsAcc/binary, Str/binary>>;
formatArgs([H | T], ArgsAcc) -> formatArgs([H | T], ArgsAcc) ->
Str = eFmt:formatBin(<<"~p">>, [H], [{charsLimit, 100}]),
Str = eFmt:format(<<"~p">>, [H], [{charsLimit, 100}]),
formatArgs(T, <<ArgsAcc/binary, Str/binary, ",">>). formatArgs(T, <<ArgsAcc/binary, Str/binary, ",">>).
formatVal(Val) -> formatVal(Val) ->
eFmt:formatBin(<<"~p">>, [Val], [{charsLimit, 500}]).
eFmt:format(<<"~p">>, [Val], [{charsLimit, 500}]).
printSillyList(L) -> 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 %% @doc Faster than proplists, but with the same API as long as you don't need to
%% handle bare atom keys %% handle bare atom keys

+ 6
- 6
src/formatter/lgFmtTer.erl Прегледај датотеку

@ -145,11 +145,11 @@ outColor(Colors, LgMsg) ->
makeStr(A) when is_atom(A) -> atom_to_binary(A); makeStr(A) when is_atom(A) -> atom_to_binary(A);
makeStr(P) when is_pid(P) -> list_to_binary(pid_to_list(P)); makeStr(P) when is_pid(P) -> list_to_binary(pid_to_list(P));
makeStr(B) when is_binary(B) -> B; 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(A) when is_atom(A) -> atom_to_list(A);
makeList(P) when is_pid(P) -> pid_to_list(P); 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, W) when is_integer(W) -> makeStr(left, makeList(A), W);
makeStr(A, {Align, W}) when is_integer(W) -> makeStr(A, {Align, W}) when is_integer(W) ->
@ -229,16 +229,16 @@ sevSeverity(?llvNone) -> <<"[o]">>.
mdJoin([], _FieldSep, BinAcc) -> mdJoin([], _FieldSep, BinAcc) ->
BinAcc; BinAcc;
mdJoin([{_K, V}], _FieldSep, BinAcc) -> mdJoin([{_K, V}], _FieldSep, BinAcc) ->
<<BinAcc/binary, (eFmt:formatBin(<<"~p">>, [V]))/binary>>;
<<BinAcc/binary, (eFmt:format(<<"~p">>, [V]))/binary>>;
mdJoin([{_K, V} | Left], FieldSep, BinAcc) -> mdJoin([{_K, V} | Left], FieldSep, BinAcc) ->
mdJoin(Left, FieldSep, <<BinAcc/binary, (eFmt:formatBin(<<"~p">>, [V]))/binary, FieldSep/binary>>).
mdJoin(Left, FieldSep, <<BinAcc/binary, (eFmt:format(<<"~p">>, [V]))/binary, FieldSep/binary>>).
mdJoin([], _IntSep, _FieldSep, BinAcc) -> mdJoin([], _IntSep, _FieldSep, BinAcc) ->
BinAcc; BinAcc;
mdJoin([{K, V}], IntSep, _FieldSep, BinAcc) -> mdJoin([{K, V}], IntSep, _FieldSep, BinAcc) ->
<<BinAcc/binary, (eFmt:formatBin(<<"~p~s~p">>, [K, IntSep, V]))/binary>>;
<<BinAcc/binary, (eFmt:format(<<"~p~s~p">>, [K, IntSep, V]))/binary>>;
mdJoin([{K, V} | Left], IntSep, FieldSep, BinAcc) -> mdJoin([{K, V} | Left], IntSep, FieldSep, BinAcc) ->
mdJoin(Left, FieldSep, <<BinAcc/binary, (eFmt:formatBin(<<"~p~s~p">>, [K, IntSep, V]))/binary, FieldSep/binary>>).
mdJoin(Left, FieldSep, <<BinAcc/binary, (eFmt:format(<<"~p~s~p">>, [K, IntSep, V]))/binary, FieldSep/binary>>).

Loading…
Откажи
Сачувај