浏览代码

ft: 代码整理

master
SisMaker 3 年前
父节点
当前提交
4de1de1065
共有 7 个文件被更改,包括 29 次插入16 次删除
  1. +1
    -1
      README.md
  2. +1
    -1
      src/backend/lgBkdConsole.erl
  3. +2
    -0
      src/backend/lgBkdFile.erl
  4. +2
    -2
      src/eLog.erl
  5. +8
    -8
      src/formatter/lgFmtTer.erl
  6. +11
    -0
      src/testl.erl
  7. +4
    -4
      src/watcher/lgHWatcherSrv.erl

+ 1
- 1
README.md 查看文件

@ -86,7 +86,7 @@ Examples:
[{pid,"Unknown Pid"}] -> "<?.?.?>" if pid is in the metadata, "Unknown Pid" if not.
[{pid, ["My pid is ", pid], ["Unknown Pid"]}] -> if pid is in the metadata print "My pid is <?.?.?>", otherwise print "Unknown Pid"
[{server,{pid, ["(", pid, ")"], ["(Unknown Server)"]}}] -> user provided server metadata, otherwise "(<?.?.?>)", otherwise "(Unknown Server)"
[{pterm, pterm_key, <<"undefined">>}] -> if a value for 'pterm_key' is found in OTP 21 (or later) persistent_term storage it is used, otherwise "undefined"
[{pterm, pterm_key, <<"undef">>}] -> if a value for 'pterm_key' is found in OTP 21 (or later) persistent_term storage it is used, otherwise "undefined"
```
错误记录器集成

+ 1
- 1
src/backend/lgBkdConsole.erl 查看文件

@ -38,7 +38,7 @@
init(Opts) ->
case isNewStyleConsole() of
false ->
Msg = "Lager's console backend is incompatible with the 'old' shell, not enabling it",
Msg = "eLog's console backend is incompatible with the 'old' shell, not enabling it",
%% be as noisy as possible, log to every possible place
try alarm_handler:set_alarm({?MODULE, "WARNING: " ++ Msg})
catch

+ 2
- 0
src/backend/lgBkdFile.erl 查看文件

@ -286,6 +286,8 @@ checkOpts([{flushQueue, FlushCfg} | Tail], IsFile) when is_boolean(FlushCfg) ->
checkOpts(Tail, IsFile);
checkOpts([{flushThr, Thr} | Tail], IsFile) when is_integer(Thr), Thr >= 0 ->
checkOpts(Tail, IsFile);
checkOpts([{id, _} | Tail], IsFile) ->
checkOpts(Tail, IsFile);
checkOpts([Other | _Tail], _IsFile) ->
{error, {invalid_opt, Other}}.

+ 2
- 2
src/eLog.erl 查看文件

@ -189,7 +189,7 @@ upLogLevelCfg(error_logger) ->
true;
upLogLevelCfg(Sink) ->
Traces = lgConfig:ptGet({Sink, trace}, []),
case Traces =/= [] of
case Traces of
[] ->
AllLogLevel = allLogLevel(getLogLevels(Sink), 0),
ets:insert(?eLogEts, {Sink, AllLogLevel}),
@ -439,7 +439,7 @@ status() ->
0 -> 1;
N -> N
end,
Status = ["Lager status:\n",
Status = ["eLog status:\n",
[begin
Level = getLogLevel(Sink, Handler),
get_sink_handler_status(Sink, Handler, Level)

+ 8
- 8
src/formatter/lgFmtTer.erl 查看文件

@ -59,9 +59,9 @@ format(LgMsg, Config, Colors) ->
].
fmtCfg([]) ->
[datetime, color, <<"[">>, severity, <<"]">>, node, <<"|">>, pid, <<"|">>, module, <<"|">>, function, <<"|">>, line, <<"|">>, message, <<"\n">>];
[datetime, <<"[">>, severity, <<"]">>, node, <<"|">>, pid, <<"|">>, module, <<"|">>, function, <<"|">>, line, <<"|">>, message, <<"\n">>];
fmtCfg(MetaWhitelist) ->
[datetime, color, <<"[">>, severity, <<"]">>, node, <<"|">>, pid, <<"|">>, module, <<"|">>, function, <<"|">>, line, <<"|">>] ++
[datetime, <<"[">>, severity, <<"]">>, node, <<"|">>, pid, <<"|">>, module, <<"|">>, function, <<"|">>, line, <<"|">>] ++
[{M, [atom_to_binary(M), <<"=">>, M, "|"], [<<>>]} || M <- MetaWhitelist] ++ [message, <<"\n">>].
% Level, Pid, Node, Module, Function, FunctionArity, Line
@ -71,8 +71,8 @@ fmtCfg(MetaWhitelist) ->
-spec output(term(), lgMsg()) -> iolist().
output(message, LgMsg) -> LgMsg#lgMsg.message;
output(datetime, LgMsg) -> LgMsg#lgMsg.datetime;
output(pid, LgMsg) -> LgMsg#lgMsg.pid;
output(node, LgMsg) -> LgMsg#lgMsg.node;
output(pid, LgMsg) -> pid_to_list(LgMsg#lgMsg.pid);
output(node, LgMsg) -> atom_to_binary(LgMsg#lgMsg.node, utf8);
output(datetime, LgMsg) -> LgMsg#lgMsg.datetime;
output(module, LgMsg) -> atom_to_binary(LgMsg#lgMsg.module, utf8);
output(function, LgMsg) -> atom_to_binary(LgMsg#lgMsg.function, utf8);
@ -92,7 +92,7 @@ output({pterm, Key}, _LgMsg) ->
output({pterm, Key, Default}, _LgMsg) ->
makeStr(getPTerm(Key, Default));
output(Prop, LgMsg) when is_atom(Prop) ->
makeStr(getMdKey(Prop, LgMsg, <<"Undefined">>));
makeStr(getMdKey(Prop, LgMsg, <<"Undef">>));
output({Prop, Default}, LgMsg) when is_atom(Prop) ->
makeStr(getMdKey(Prop, LgMsg, output(Default, LgMsg)));
output({Prop, Present, Absent}, LgMsg) when is_atom(Prop) ->
@ -114,8 +114,8 @@ output(Other, _) -> makeStr(Other).
output(message, LgMsg, _Width) -> LgMsg#lgMsg.message;
output(datetime, LgMsg, _Width) -> LgMsg#lgMsg.datetime;
output(pid, LgMsg, _Width) -> LgMsg#lgMsg.pid;
output(node, LgMsg, _Width) -> LgMsg#lgMsg.node;
output(pid, LgMsg, _Width) -> pid_to_list(LgMsg#lgMsg.pid);
output(node, LgMsg, _Width) -> atom_to_binary(LgMsg#lgMsg.node, utf8);
output(module, LgMsg, _Width) -> atom_to_binary(LgMsg#lgMsg.module, utf8);
output(function, LgMsg, _Width) -> atom_to_binary(LgMsg#lgMsg.function, utf8);
output(line, LgMsg, _Width) -> integer_to_binary(LgMsg#lgMsg.line);
@ -132,7 +132,7 @@ output({metadata, IntSep, FieldSep}, LgMsg, _Width) ->
output({pterm, Key}, _LgMsg, _Width) -> makeStr(getPTerm(Key, <<"">>));
output({pterm, Key, Default}, _LgMsg, _Width) -> makeStr(getPTerm(Key, Default));
output(Prop, LgMsg, Width) when is_atom(Prop) ->
makeStr(getMdKey(Prop, LgMsg, <<"Undefined">>), Width);
makeStr(getMdKey(Prop, LgMsg, <<"Undef">>), Width);
output({Prop, Default}, LgMsg, Width) when is_atom(Prop) ->
makeStr(getMdKey(Prop, LgMsg, output(Default, LgMsg)), Width);
output(Other, _, Width) -> makeStr(Other, Width).

+ 11
- 0
src/testl.erl 查看文件

@ -0,0 +1,11 @@
-module(testl).
-include("eLog.hrl").
-compile([export_all, nowarn_export_all]).
test(Msg) ->
?lgDebug("IMY************* ~p~n", [Msg]).
tt() ->
?lgError("IMYYYYYYYYYYYYYYY") .

+ 4
- 4
src/watcher/lgHWatcherSrv.erl 查看文件

@ -61,7 +61,7 @@ handleInfo({gen_event_EXIT, Module, {'EXIT', {kill_me, [_KillerHwm, KillerReinst
_ = timer:apply_after(KillerReinstallAfter, lager_app, start_handler, [Sink, Module, Config]),
{stop, normal, State};
handleInfo({gen_event_EXIT, Module, Reason}, #state{module = Module, config = Config, sink = Sink} = State) ->
case eLog:log(error, self(), "Lager event handler ~p exited with reason ~s", [Module, lgErrLoggerH:formatReason(Reason)]) of
case eLog:log(error, self(), "eLog event handler ~p exited with reason ~s", [Module, lgErrLoggerH:formatReason(Reason)]) of
ok ->
installHandler(Module, Config, Sink);
{error, _} ->
@ -105,17 +105,17 @@ installHandler(Module, Config, Sink) ->
end,
case Ret of
ok ->
?INT_LOG(debug, "Lager installed handler ~p into ~p ~p", [Module, Sink, whereis(Sink)]),
?INT_LOG(debug, "eLog installed handler ~p into ~p ~p", [Module, Sink, whereis(Sink)]),
%eLog:updateLogevelCfg(Sink),
ok;
{error, {fatal, Reason}} ->
?INT_LOG(error, "Lager fatally failed to install handler ~p into ~p, NOT retrying: ~p", [Module, Sink, Reason]),
?INT_LOG(error, "eLog fatally failed to install handler ~p into ~p, NOT retrying: ~p", [Module, Sink, Reason]),
%% tell ourselves to stop
self() ! stop,
ok;
Error ->
%% try to reinstall it later
?INT_LOG(error, "Lager failed to install handler ~p into ~p, retrying later : ~p", [Module, Sink, Error]),
?INT_LOG(error, "eLog failed to install handler ~p into ~p, retrying later : ~p", [Module, Sink, Error]),
erlang:send_after(5000, self(), mReinstallHandler),
ok
end.

正在加载...
取消
保存