Преглед на файлове

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(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),

+ 8
- 8
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)]),

+ 7
- 7
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.

+ 13
- 13
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, <<Formatted/binary, " in ", Formatted2/binary>>};
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}]),
<<ArgsAcc/binary, Str/binary>>;
formatArgs([H | T], ArgsAcc) ->
Str = eFmt:formatBin(<<"~p">>, [H], [{charsLimit, 100}]),
Str = eFmt:format(<<"~p">>, [H], [{charsLimit, 100}]),
formatArgs(T, <<ArgsAcc/binary, Str/binary, ",">>).
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

+ 6
- 6
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) ->
<<BinAcc/binary, (eFmt:formatBin(<<"~p">>, [V]))/binary>>;
<<BinAcc/binary, (eFmt:format(<<"~p">>, [V]))/binary>>;
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) ->
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(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>>).

Зареждане…
Отказ
Запис