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

fx: gen_emm返回优化

master
SisMaker пре 3 година
родитељ
комит
3a427c48fb
6 измењених фајлова са 33 додато и 32 уклоњено
  1. +6
    -6
      src/backend/lgBkdConsole.erl
  2. +13
    -12
      src/backend/lgBkdFile.erl
  3. +8
    -8
      src/backend/lgBkdThrottle.erl
  4. +1
    -1
      src/crashLog/lgCrashLog.erl
  5. +1
    -1
      src/eLog.erl
  6. +4
    -4
      src/mgrKiller/lgMgrKiller.erl

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

@ -75,19 +75,19 @@ checkOpts([H | _]) ->
{error, {invalid_opt, H}}.
handleCall(mGetLogLevel, State) ->
{reply, State#state.level, State};
{reply, State#state.level};
handleCall({mSetLogLevel, Level}, State) ->
case lgUtil:validateLogLevel(Level) of
false ->
{reply, {error, bad_loglevel}, State};
{reply, {error, bad_loglevel}};
LevelMask ->
{reply, ok, State#state{level = LevelMask}}
end;
handleCall({mRotate, _}, State) ->
{reply, ok, State};
handleCall(_Msg, State) ->
handleCall({mRotate, _}, _State) ->
{reply, ok};
handleCall(_Msg, _State) ->
?ERR(<<"~p call receive unexpect msg ~p ~n ">>, [?MODULE, _Msg]),
{reply, ok, State}.
{reply, ok}.
handleEvent({mWriteLog, Message}, #state{level = Level, out = Out, fmtTer = FmtTer, fmtCfg = FmtCfg, colors = Colors, id = ID}) ->
case lgUtil:isLoggAble(Message, Level, ID) of

+ 13
- 12
src/backend/lgBkdFile.erl Прегледај датотеку

@ -96,21 +96,20 @@ init(Opts) ->
{ok, TemState#state{flap = true}}
end.
handleCall(mGetLogLevel, #state{level = Level} = State) ->
{reply, Level, State};
handleCall(mGetLogLevel, #state{level = Level}) ->
{reply, Level};
handleCall({mSetLogLevel, Level}, #state{fBName = FBName} = State) ->
case lgUtil:validateLogLevel(Level) of
false ->
{reply, {error, bad_loglevel}, State};
{reply, {error, bad_loglevel}};
LevelMask ->
?INT_LOG(?llvNotice, <<"Changed loglevel of ~s to ~p">>, [FBName, Level]),
{reply, ok, State#state{level = LevelMask}}
end;
handleCall({mSetLogHwm, Hwm}, #state{shaper = Shaper, fBName = FBName} = State) ->
case checkOpts([{hwm, Hwm}], true) of
false ->
{reply, {error, badHwm}, State};
{reply, {error, badHwm}};
_ ->
NewShaper = Shaper#lgShaper{hwm = Hwm},
?INT_LOG(?llvNotice, <<"Changed loghwm of ~ts to ~p">>, [FBName, Hwm]),
@ -119,9 +118,9 @@ handleCall({mSetLogHwm, Hwm}, #state{shaper = Shaper, fBName = FBName} = State)
handleCall(mRotate, State = #state{fBName = FBName}) ->
{ok, NewState} = handleInfo({mRotate, FBName}, State),
{reply, ok, NewState};
handleCall(_Msg, State) ->
handleCall(_Msg, _State) ->
?ERR(<<"~p call receive unexpect msg ~p ~n ">>, [?MODULE, _Msg]),
{reply, ok, State}.
{reply, ok}.
handleEvent({mWriteLog, Message}, #state{fBName = FBName, level = Level, shaper = Shaper, fmtTer = FmtTer, fmtCfg = FmtCfg} = State) ->
case lgUtil:isLoggAble(Message, Level, {lgBkdFile, FBName}) of
@ -129,7 +128,7 @@ handleEvent({mWriteLog, Message}, #state{fBName = FBName, level = Level, shaper
#lgMsg{timestamp = Timestamp, severity = Severity} = Message,
case lgUtil:checkHwm(Shaper) of
{true, _Drop, NewShaper} ->
{ok, writeLog(State#state{shaper = NewShaper}, Timestamp, Severity, FmtTer:format(Message, FmtCfg))};
{noreply, writeLog(State#state{shaper = NewShaper}, Timestamp, Severity, FmtTer:format(Message, FmtCfg))};
{drop, Drop, NewShaper} ->
TemState =
case Drop =< 0 of
@ -142,9 +141,9 @@ handleEvent({mWriteLog, Message}, #state{fBName = FBName, level = Level, shaper
ReportMsg = #lgMsg{severity = ?llvWarning, pid = self(), node = node(), module = ?MODULE, function = ?FUNCTION_NAME, line = ?LINE, metadata = [], datetime = NowStr, timestamp = NowMs, message = ReportStr, destinations = []},
writeLog(State, NowMs, ?llvWarning, FmtTer:format(ReportMsg, FmtCfg))
end,
{ok, writeLog(TemState#state{shaper = NewShaper}, Timestamp, Severity, FmtTer:format(Message, FmtCfg))};
{noreply, writeLog(TemState#state{shaper = NewShaper}, Timestamp, Severity, FmtTer:format(Message, FmtCfg))};
{false, _, NewShaper} ->
{ok, State#state{shaper = NewShaper}}
{noreply, State#state{shaper = NewShaper}}
end;
_ ->
kpS
@ -156,7 +155,9 @@ handleEvent(_Msg, _State) ->
handleInfo({mRotate, FBName}, #state{fBName = FBName, date = Date} = State) ->
NewState = closeFile(State),
scheduleRotation(Date, FBName),
{ok, NewState};
{noreply, NewState};
handleInfo({mRotate, _FBName}, _State) ->
kpS;
handleInfo({mShaperExpired, FBName}, #state{shaper = Shaper, fBName = FBName, fmtTer = FmtTer, fmtCfg = FmtCfg} = State) ->
case Shaper#lgShaper.dropped of
0 ->
@ -168,7 +169,7 @@ handleInfo({mShaperExpired, FBName}, #state{shaper = Shaper, fBName = FBName, fm
ReportMsg = #lgMsg{severity = ?llvWarning, pid = self(), node = node(), module = ?MODULE, function = ?FUNCTION_NAME, line = ?LINE, metadata = [], datetime = NowStr, timestamp = NowMs, message = ReportStr, destinations = []},
writeLog(State, NowMs, ?llvWarning, FmtTer:format(ReportMsg, FmtCfg))
end,
{ok, State#state{shaper = Shaper#lgShaper{dropped = 0}}};
{noreply, State#state{shaper = Shaper#lgShaper{dropped = 0}}};
handleInfo(_Msg, _State) ->
?ERR(<<"~p info receive unexpect msg ~p ~n ">>, [?MODULE, _Msg]),
kpS.

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

@ -31,13 +31,13 @@ init([Sink, Hwm, Window]) ->
lgConfig:ptSet({Sink, async}, true),
{ok, #state{sink = Sink, hwm = Hwm, window = Hwm - Window}}.
handleCall(mGetLogLevel, State) ->
{reply, ?llvNone, State};
handleCall({mSetLogLevel, _Level}, State) ->
{reply, ok, State};
handleCall(_Msg, State) ->
handleCall(mGetLogLevel, _State) ->
{reply, ?llvNone};
handleCall({mSetLogLevel, _Level}, _State) ->
{reply, ok};
handleCall(_Msg, _State) ->
?ERR(<<"~p call receive unexpect msg ~p ~n ">>, [?MODULE, _Msg]),
{reply, ok, State}.
{reply, ok}.
handleEvent({mWriteLog, _Message}, #state{sink = Sink, hwm = Hwm, window = Window, async = Async} = State) ->
{_, MsgLen} = erlang:process_info(self(), message_queue_len),
@ -45,11 +45,11 @@ handleEvent({mWriteLog, _Message}, #state{sink = Sink, hwm = Hwm, window = Windo
MsgLen > Hwm andalso Async ->
%% need to flip to sync mode
lgConfig:ptSet({Sink, async}, false),
{ok, State#state{async = false}};
{noreply, State#state{async = false}};
MsgLen < Window andalso not Async ->
%% need to flip to async mode
lgConfig:ptSet({Sink, async}, true),
{ok, State#state{async = true}};
{noreply, State#state{async = true}};
true ->
%% nothing needs to change
kpS

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

@ -79,7 +79,7 @@ handleInfo({mWriteLog, Event}, State) ->
handleInfo(mRotate, #state{date = Date} = State) ->
NewState = closeFile(State),
scheduleRotation(Date),
{ok, NewState};
{noreply, NewState};
handleInfo(_Msg, _State) ->
?ERR(<<"~p info receive unexpect msg ~p ~n ">>, [?MODULE, _Msg]),
kpS.

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

@ -501,7 +501,7 @@ unsafeFormat(Fmt, Args) ->
safeFormat(Fmt, Args, Limit) ->
try eFmt:formatBin(Fmt, Args, Limit)
catch
_C:_R:_S ->
_:_ ->
eFmt:formatBin(<<"FORMAT ERROR UNSAFE: ~p ~p">>, [Fmt, Args], Limit)
end.

+ 4
- 4
src/mgrKiller/lgMgrKiller.erl Прегледај датотеку

@ -41,16 +41,16 @@ handleCall(_Request, State) ->
{reply, ok, State}.
%% 使
handleEvent({mWriteLog, _Message}, State = #state{killerHwm = KillerHwm, killerReTime = KillerReinstallAfter}) ->
handleEvent({mWriteLog, _Message}, #state{killerHwm = KillerHwm, killerReTime = KillerReinstallAfter}) ->
{_, Len} = process_info(self(), message_queue_len),
case Len > KillerHwm of
true ->
exit({kill_me, [KillerHwm, KillerReinstallAfter]});
_ ->
{okpan>, State}
kpS
end;
handleEvent(_Event, State) ->
{okpan>, State}.
handleEvent(_Event, _State) ->
kpS.
handleInfo(_Info, State) ->
{ok, State}.

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