From 4de1de1065a05fd6ef320ebcffcce1a632be52e8 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Fri, 2 Jul 2021 17:17:47 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/backend/lgBkdConsole.erl | 2 +- src/backend/lgBkdFile.erl | 2 ++ src/eLog.erl | 4 ++-- src/formatter/lgFmtTer.erl | 16 ++++++++-------- src/testl.erl | 11 +++++++++++ src/watcher/lgHWatcherSrv.erl | 8 ++++---- 7 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 src/testl.erl diff --git a/README.md b/README.md index be1024f..21eb205 100644 --- a/README.md +++ b/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" ``` 错误记录器集成 diff --git a/src/backend/lgBkdConsole.erl b/src/backend/lgBkdConsole.erl index 17c685a..4b6fa4b 100644 --- a/src/backend/lgBkdConsole.erl +++ b/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 diff --git a/src/backend/lgBkdFile.erl b/src/backend/lgBkdFile.erl index 3134d37..2ec4164 100644 --- a/src/backend/lgBkdFile.erl +++ b/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}}. diff --git a/src/eLog.erl b/src/eLog.erl index 2f1d5b7..f56a737 100644 --- a/src/eLog.erl +++ b/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) diff --git a/src/formatter/lgFmtTer.erl b/src/formatter/lgFmtTer.erl index d978000..aafc24e 100644 --- a/src/formatter/lgFmtTer.erl +++ b/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). diff --git a/src/testl.erl b/src/testl.erl new file mode 100644 index 0000000..1834437 --- /dev/null +++ b/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") . diff --git a/src/watcher/lgHWatcherSrv.erl b/src/watcher/lgHWatcherSrv.erl index fb6ca0c..412d4b7 100644 --- a/src/watcher/lgHWatcherSrv.erl +++ b/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.