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