diff --git a/include/rumDef.hrl b/include/rumDef.hrl index c49b98f..0d5b085 100644 --- a/include/rumDef.hrl +++ b/include/rumDef.hrl @@ -1,5 +1,4 @@ -include("rumCom.hrl"). --include("rumMsg.hrl"). %% 应用名字 -define(RumAppName, eRum). @@ -97,7 +96,22 @@ , filter = fun(_) -> false end :: fun() }). +-record(rumMsg, { + severity :: rumAtomLevel() + , pid :: pid() + , node :: node() + , module :: module() + , function :: atom() + , line :: integer() + , metadata :: [tuple()] + , datetime :: binary() + , timestamp :: non_neg_integer() + , message :: list() + , destinations :: list() +}). + -type rumShaper() :: #rumShaper{}. +-type rumMsg() :: #rumMsg{}. -type rumAtomLevel() :: none | debug | info | notice | warning | error | critical | alert | emergency. -type rumMaskLevel() :: 0..256. @@ -110,8 +124,7 @@ -define(RunShouldLog(Level), (rumUtil:levelToNum(Level) band rumConfig:get(?RumDefSink)) /= 0). -define(RunNotify(Level, Pid, Format, Args), - LagerMsg = ?newMsg(Level, Pid, node(), ?MODULE, ?FUNCTION_NAME, ?LINE, [], [], rumUtil:nowMs(), eFmt:formatBin(Format, Args)), - gen_emm:info_notify(?RumDefSink, {mWriteLog, LagerMsg})). + gen_emm:info_notify(?RumDefSink, {mWriteLog, #rumMsg{severity = Level, pid = Pid, node = node(), module = ?MODULE, function = ?FUNCTION_NAME, line = ?LINE, metadata = [], datetime = rumUtil:msToBinStr(), timestamp = rumTime:nowMs(), message = eFmt:formatBin(Format, Args), destinations = []}})). %%仅供内部使用仅内部非阻塞日志记录调用,当我们仍在启动大型啤酒时尝试进行日志记录(通常为错误)时,会有一些特殊处理。 -define(INT_LOG(Level, Format, Args), diff --git a/include/rumMsg.hrl b/include/rumMsg.hrl deleted file mode 100644 index 119eb66..0000000 --- a/include/rumMsg.hrl +++ /dev/null @@ -1,33 +0,0 @@ --ifndef(__RumMsg__). --define(__RumMsg__, 1). - --record(rumMsg, { - severity :: rumAtomLevel() - , pid :: pid() - , node :: node() - , module :: module() - , function :: atom() - , file :: atom() - , line :: integer() - , metadata :: [tuple()] - , datetime :: binary() - , timestamp :: non_neg_integer() - , message :: list() - , destinations :: list() -}). - --define(newMsg(Severity, Pid, Node, Module, Function, Line, Metadata, Destinations, TimeMs, Msg), - #rumMsg{ - severity = Severity - , pid =Pid - , node = Node - , module = Module - , function = Function - , line =Line - , metadata =Metadata - , datetime = rumUtil:msToBinStr(TimeMs) - , timestamp = TimeMs - , message = Msg - , destinations = Destinations - }). --endif. \ No newline at end of file diff --git a/src/backend/rumBkdFile.erl b/src/backend/rumBkdFile.erl index 7b0b462..3a935f3 100644 --- a/src/backend/rumBkdFile.erl +++ b/src/backend/rumBkdFile.erl @@ -123,20 +123,23 @@ handleCall(_Msg, State) -> handleEvent({mWriteLog, Message}, #state{fileName = FileName, level = Level, shaper = Shaper, formatTer = FormatTer, formatCfg = FormatCfg} = State) -> case rumUtil:isLoggAble(Message, Level, {rumBkdFile, FileName}) of true -> + #rumMsg{timestamp = Timestamp, severity = Severity} = Message, case rumUtil:checkHwm(Shaper) of {true, _Drop, NewShaper} -> - {ok, writeLog(State#state{shaper = NewShaper}, rumMsg:timestamp(Message), rumMsg:severity_as_int(Message), FormatTer:format(Message, FormatCfg))}; + {ok, writeLog(State#state{shaper = NewShaper}, Timestamp, Severity, FormatTer:format(Message, FormatCfg))}; {drop, Drop, NewShaper} -> TemState = case Drop =< 0 of true -> State; _ -> - Report = eFmt:format(<<"rumBkdFile dropped ~p messages in the last second that exceeded the limit of ~p messages/sec">>, [Drop, NewShaper#rumShaper.hwm]), - ReportMsg = rumMsg:new(Report, warning, [], []), - writeLog(State, rumMsg:timestamp(ReportMsg), rumMsg:severity_as_int(ReportMsg), FormatTer:format(ReportMsg, FormatCfg)) + ReportStr = eFmt:format(<<"rumBkdFile dropped ~p messages in the last second that exceeded the limit of ~p messages/sec">>, [Drop, NewShaper#rumShaper.hwm]), + NowMs = rumTime:nowMs(), + NowStr = rumUtil:msToBinStr(NowMs), + ReportMsg = #rumMsg{severity = ?warning, pid = self(), node = node(), module = ?MODULE, function = ?FUNCTION_NAME, line = ?LINE, metadata = [], datetime = NowStr, timestamp = NowMs, message = ReportStr, destinations = []}, + writeLog(State, NowMs, ?warning, FormatTer:format(ReportMsg, FormatCfg)) end, - {ok, writeLog(TemState#state{shaper = NewShaper}, rumMsg:timestamp(Message), rumMsg:severity_as_int(Message), FormatTer:format(Message, FormatCfg))}; + {ok, writeLog(TemState#state{shaper = NewShaper}, Timestamp, Severity, FormatTer:format(Message, FormatCfg))}; {false, _, NewShaper} -> {ok, State#state{shaper = NewShaper}} end; @@ -157,9 +160,11 @@ handleInfo({mShaperExpired, Name}, #state{shaper = Shaper, fileName = Name, form 0 -> ignore; Dropped -> - Report = eFmt:format(<<"rumBkdFile dropped ~p messages in the last second that exceeded the limit of ~p messages/sec">>, [Dropped, Shaper#rumShaper.hwm]), - ReportMsg = rumMsg:new(Report, warning, [], []), - writeLog(State, rumMsg:timestamp(ReportMsg), rumMsg:severity_as_int(ReportMsg), FormatTer:format(ReportMsg, FormatCfg)) + ReportStr = eFmt:format(<<"rumBkdFile dropped ~p messages in the last second that exceeded the limit of ~p messages/sec">>, [Dropped, Shaper#rumShaper.hwm]), + NowMs = rumTime:nowMs(), + NowStr = rumUtil:msToBinStr(NowMs), + ReportMsg = #rumMsg{severity = ?warning, pid = self(), node = node(), module = ?MODULE, function = ?FUNCTION_NAME, line = ?LINE, metadata = [], datetime = NowStr, timestamp = NowMs, message = ReportStr, destinations = []}, + writeLog(State, NowMs, ?warning, FormatTer:format(ReportMsg, FormatCfg)) end, {ok, State#state{shaper = Shaper#rumShaper{dropped = 0, mps = 0, lastTime = rumTime:now()}}}; handleInfo(_Msg, _State) -> diff --git a/src/eRum.erl b/src/eRum.erl index 331493c..216f788 100644 --- a/src/eRum.erl +++ b/src/eRum.erl @@ -2,7 +2,6 @@ -include("rumDef.hrl"). --include("rumMsg.hrl"). -include("rumCom.hrl"). -compile(inline). @@ -101,17 +100,20 @@ do_log_impl(Severity, Pid, Node, Module, Function, Line, Metadata, Format, Args, {rumUtil:check_traces(Metadata, Severity, TraceFilters, []), whereis(?RumTrackSink)} end, - Msg = ?IIF(Args /= [] andalso Args /= undefined, ?IIF(Safety == safe, eFmt:formatBin(Format, [Args], [{charsLimit, Size}]), eFmt:formatBin(Format, [Args])), Format), - LagerMsg = ?newMsg(Severity, Pid, Node, Module, Function, Line, Metadata, Destinations, rumUtil:nowMs(), Msg), + MsgStr = ?IIF(Args /= [] andalso Args /= undefined, ?IIF(Safety == safe, eFmt:formatBin(Format, [Args], [{charsLimit, Size}]), eFmt:formatBin(Format, [Args])), Format), + NowMs = rumTime:nowMs(), + NowStr = rumUtil:msToBinStr(NowMs), + RumMsg = #rumMsg{severity = Severity, pid = Pid, node = Node, module = Module, function = Function, line = Line, metadata = Metadata, datetime = NowStr, timestamp = NowMs, message = MsgStr, destinations = Destinations}, + case rumConfig:get({Sink, async}, false) of true -> - gen_emm:info_notify(Sink, {mWriteLog, LagerMsg}); + gen_emm:info_notify(Sink, {mWriteLog, RumMsg}); false -> - gen_emm:call_notify(Sink, {mWriteLog, LagerMsg}) + gen_emm:call_notify(Sink, {mWriteLog, RumMsg}) end, case TraceSinkPid /= undefined of true -> - gen_emm:info_notify(TraceSinkPid, {mWriteLog, LagerMsg}); + gen_emm:info_notify(TraceSinkPid, {mWriteLog, RumMsg}); false -> ok end. diff --git a/src/eRum1.erl b/src/eRum1.erl index 8aa4aca..7c600b3 100644 --- a/src/eRum1.erl +++ b/src/eRum1.erl @@ -1,7 +1,6 @@ -module(eRum1). -include("rumDef.hrl"). --include("rumMsg.hrl"). -include("rumCom.hrl"). @@ -119,16 +118,19 @@ do_log_impl(Severity, Pid, Node, Module, Function, _File, Line, Metadata, Format _ -> Format end, - LagerMsg = ?newMsg(Severity, Pid, Node, Module, Function, Line, Metadata, Destinations, rumUtil:nowMs(), Msg), + NowMs = rumTime:nowMs(), + NowStr = rumUtil:msToBinStr(NowMs), + RumMsg = #rumMsg{severity = Severity, pid = Pid, node = Node, module = Module, function = Function, line = Line, metadata = Metadata, datetime = NowStr, timestamp = NowMs, message = Msg, destinations = Destinations}, + case rumConfig:get({Sink, async}, false) of true -> - gen_emm:info_notify(SinkPid, {mWriteLog, LagerMsg}); + gen_emm:info_notify(SinkPid, {mWriteLog, RumMsg}); _ -> - gen_emm:call_notify(SinkPid, {mWriteLog, LagerMsg}) + gen_emm:call_notify(SinkPid, {mWriteLog, RumMsg}) end, case TraceSinkPid /= undefined of true -> - gen_emm:info_notify(TraceSinkPid, {mWriteLog, LagerMsg}); + gen_emm:info_notify(TraceSinkPid, {mWriteLog, RumMsg}); false -> ok end; diff --git a/src/utils/rumMsg.erl b/src/utils/rumMsg.erl index 6118a75..a596de1 100644 --- a/src/utils/rumMsg.erl +++ b/src/utils/rumMsg.erl @@ -1,7 +1,6 @@ -module(rumMsg). -include("rumDef.hrl"). --include("rumMsg.hrl"). -export([new/4, new/5]). -export([message/1]).