@ -95,33 +95,19 @@ scheduleRotation(Date) ->
erlang : send_after ( rumUtil : calcNextRotateMs ( Date ) , self ( ) , mRotate ) ,
ok .
% % == == = Begin code lifted from riak_err == == =
- spec limited_fmt ( string ( ) , list ( ) , integer ( ) ) - > iolist ( ) .
% % @ doc Format Fmt and Args similar to what io_lib : format / 2 does but with
% % limits on how large the formatted string may be .
% %
% % If the Args list ' s size is larger than TermMaxSize , then the
% % formatting is done by trunc_io : print / 2 , where FmtMaxBytes is used
% % to limit the formatted string ' s size .
limited_fmt ( Fmt , Args , FmtMaxBytes ) - >
eRum : safe_format ( Fmt , Args , FmtMaxBytes ) .
limited_str ( Term , FmtMaxBytes ) - >
{ Str , _ } = rumTruncIo : print ( Term , FmtMaxBytes ) ,
Str .
other_node_suffix ( Pid ) when node ( Pid ) =/= node ( ) - >
" ** at node " ++ atom_to_list ( node ( Pid ) ) ++ " ** \n " ;
other_node_suffix ( _ ) - >
" " .
otherNodeSuffix ( Pid ) when node ( Pid ) =/= node ( ) - >
PidNode = node ( Pid ) ,
case PidNode =/= node ( ) of
true - >
< < " ** at node " , ( atom_to_binary ( node ( Pid ) , utf8 ) ) / binary , " ** \n " > > ;
_ - >
< < " " > >
end .
perhaps_a_sasl_r eport ( error_report , { Pid , Type , Report } , FmtMaxBytes ) - >
case rumStdlib : is_my_error_r eport ( Type ) of
perhapsSaslReport ( error_report , { Pid , Type , Report } , FmtMaxBytes ) - >
case rumStdlib : isErrorReport ( Type ) of
true - >
{ sasl_type_to_report_head ( Type ) , Pid ,
sasl_limited_str ( Type , Report , FmtMaxBytes ) , true } ;
{ saslTypeToReportHead ( Type ) , Pid , saslLimitedStr ( Type , Report , FmtMaxBytes ) , true } ;
false - >
{ ignore , ignore , ignore , false }
end ;
@ -133,79 +119,74 @@ perhaps_a_sasl_report(error_report, {Pid, Type, Report}, FmtMaxBytes) ->
% false - >
% { ignore , ignore , ignore , false }
% end ;
perhaps_a_sasl_r eport ( _ , _ , _ ) - >
perhapsSaslR eport ( _ , _ , _ ) - >
{ ignore , ignore , ignore , false } .
sasl_type_to_report_h ead ( supervisor_report ) - >
" SUPERVISOR REPORT " ;
sasl_type_to_report_h ead ( crash_report ) - >
" CRASH REPORT " ;
sasl_type_to_report_h ead ( progress ) - >
" PROGRESS REPORT " .
saslTypeToReportH ead ( supervisor_report ) - >
< < " SUPERVISOR REPORT "; > > ; ;
saslTypeToReportH ead ( crash_report ) - >
< < " CRASH REPORT "; > > ; ;
saslTypeToReportH ead ( progress ) - >
< < " PROGRESS REPORT "; > > ; .
sasl_limited_s tr ( supervisor_report , Report , FmtMaxBytes ) - >
saslLimitedS tr ( supervisor_report , Report , FmtMaxBytes ) - >
Name = rumStdlib : sup_get ( supervisor , Report ) ,
Context = rumStdlib : sup_get ( errorContext , Report ) ,
Reason = rumStdlib : sup_get ( reason , Report ) ,
Offender = rumStdlib : sup_get ( offender , Report ) ,
FmtString = " Supervisor: ~p ~n Context: ~p ~n Reason: "
" ~s ~n Offender: ~s ~n ~n " ,
{ ReasonStr , _ } = rumTruncIo : print ( Reason , FmtMaxBytes ) ,
{ OffenderStr , _ } = rumTruncIo : print ( Offender , FmtMaxBytes ) ,
io_lib : format ( FmtString , [ Name , Context , ReasonStr , OffenderStr ] ) ;
sasl_limited_s tr ( progress , Report , FmtMaxBytes ) - >
FmtString = < < " Supervisor: ~p ~n Context: ~p ~n Reason: "
" ~s ~n Offender: ~s ~n ~n " > > ,
ReasonStr = eFmt : formatBin ( < < " ~p " > > , [ Reason ] , [ { charsLimit , FmtMaxBytes } ] ) ,
OffenderStr = eFmt : formatBin ( < < " ~p " > > , [ Offender ] , [ { charsLimit , FmtMaxBytes } ] ) ,
eFmt : format ( FmtString , [ Name , Context , ReasonStr , OffenderStr ] ) ;
saslLimitedS tr ( progress , Report , FmtMaxBytes ) - >
[ begin
{ Str , _ } = rumTruncIo : print ( Data , FmtMaxBytes ) ,
io_lib : format ( " ~16w : ~s ~n " , [ Tag , Str ] )
BinStr = eFmt : formatBin ( < < " ~p " > > , [ Data ] , [ { charsLimit , FmtMaxBytes } ] ) ,
eFmt : formatBin ( " ~16w : ~s ~n " , [ Tag , Bin Str] )
end | | { Tag , Data } < - Report ] ;
sasl_limited_s tr ( crash_report , Report , FmtMaxBytes ) - >
saslLimitedS tr ( crash_report , Report , FmtMaxBytes ) - >
rumStdlib : proc_lib_format ( Report , FmtMaxBytes ) .
writeLog ( Event , #state { fileName = Name , fd = FD , inode = Inode , ctime = Ctime , flap = Flap ,
maxFmtSize = FmtMaxBytes , maxFileSize = RotSize , count = Count , rotator = Rotator } = State ) - >
writeLog ( Event , #state { fileName = FileName , fd = FD , inode = Inode , ctime = Ctime , flap = Flap , maxFmtSize = FmtMaxBytes , maxFileSize = RotSize , count = Count , rotator = Rotator } = State ) - >
% % borrowed from riak_err
{ ReportStr , Pid , MsgStr , _ ErrorP } =
case Event of
{ error , _ GL , { Pid1 , Fmt , Args } } - >
{ " ERROR REPORT " , Pid1 , limited_fmt ( Fmt , Args , FmtMaxBytes ) , true } ;
{ < < " ERROR REPORT " > > , Pid1 , eFmt : formatBin ( Fmt , Args , [ { charsLimit , FmtMaxBytes } ] ) , true } ;
{ error_report , _ GL , { Pid1 , std_error , Rep } } - >
{ " ERROR REPORT " , Pid1 , limited_str ( Rep , FmtMaxBytes ) ++ " \n " , true } ;
{ < < " ERROR REPORT " > > , Pid1 , eFmt : formatBin ( < < " ~p \n " > > , [ Rep ] , [ { charsLimit , FmtMaxBytes } ] ) , true } ;
{ error_report , _ GL , Other } - >
perhaps_a_sasl_r eport ( error_report , Other , FmtMaxBytes ) ;
perhapsSaslR eport ( error_report , Other , FmtMaxBytes ) ;
_ - >
{ ignore , ignore , ignore , false }
end ,
if ReportStr == ignore - >
{ ok , State } ;
true - >
case Rotator : ensureLogfile ( Name , FD , Inode , Ctime , false ) of
{ ok , { _ FD , _ Inode , _ Ctime , Size } } when RotSize / = 0 , Size > RotSize - >
_ = Rotator : rotateLogfile ( Name , Count ) ,
handleCast ( { mWriteLog , Event } , State ) ;
{ ok , { NewFD , NewInode , NewCtime , _ Size } } - >
TimeBinStr = rumUtil : msToBinStr ( ) ,
Time = [ TimeBinStr , " = " , ReportStr , " ==== \n " ] ,
NodeSuffix = other_node_suffix ( Pid ) ,
Msg = io_lib : format ( " ~s ~s ~s " , [ Time , MsgStr , NodeSuffix ] ) ,
case file : write ( NewFD , unicode : characters_to_binary ( Msg ) ) of
{ error , Reason } when Flap == false - >
? INT_LOG ( error , " Failed to write log message to file ~ ts: ~s " ,
[ Name , file : format_error ( Reason ) ] ) ,
{ ok , State #state { fd = NewFD , inode = NewInode , ctime = NewCtime , flap = true } } ;
ok - >
{ ok , State #state { fd = NewFD , inode = NewInode , ctime = NewCtime , flap = false } } ;
case ReportStr of
ignore - >
{ ok , State } ;
_ - >
case Rotator : ensureLogfile ( FileName , FD , Inode , Ctime , false ) of
{ ok , NewFD , NewInode , NewCtime , FileSize } - >
case RotSize > 0 andalso FileSize > RotSize of
true - >
_ = Rotator : rotateLogfile ( FileName , Count ) ,
handleCast ( { mWriteLog , Event } , State ) ;
_ - >
{ ok , State #state { fd = NewFD , inode = NewInode , ctime = NewCtime } }
TimeBinStr = rumUtil : msToBinStr ( ) ,
Time = [ TimeBinStr , < < " = " > > , ReportStr , < < " ==== \n " > > ] ,
NodeSuffix = otherNodeSuffix ( Pid ) ,
Msg = eFmt : formatBin ( " ~s ~s ~s " , [ Time , MsgStr , NodeSuffix ] ) ,
case file : write ( NewFD , unicode : characters_to_binary ( Msg ) ) of
{ error , Reason } when Flap == false - >
? INT_LOG ( error , " Failed to write log message to file ~ ts: ~s " , [ FileName , file : format_error ( Reason ) ] ) ,
{ ok , State #state { fd = NewFD , inode = NewInode , ctime = NewCtime , flap = true } } ;
ok - >
{ ok , State #state { fd = NewFD , inode = NewInode , ctime = NewCtime , flap = false } } ;
_ - >
{ ok , State #state { fd = NewFD , inode = NewInode , ctime = NewCtime } }
end
end ;
{ error , Reason } - >
case Flap of
true - >
{ ok , State } ;
_ - >
? INT_LOG ( error , " Failed to reopen crash log ~ ts with error: ~s " ,
[ Name , file : format_error ( Reason ) ] ) ,
{ ok , State #state { flap = true } }
end
? IIF ( Flap , { ok , State } , begin ? INT_LOG ( error , " Failed to reopen crash log ~ ts with error: ~s " , [ FileName , file : format_error ( Reason ) ] ) , { ok , State #state { flap = true } } end )
end
end .