X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fengine%2Fe_log.pas;h=ed4cfe525f4479957cca8754c690a99be9f64b4c;hb=5e0a71e1d35a9037be80c8912060a913d0e98b18;hp=afc638cac7be82a9d7af6a0f1eb764811adf4eb8;hpb=223356cbae3197afc861efa6241c4ae91bd92885;p=d2df-sdl.git diff --git a/src/engine/e_log.pas b/src/engine/e_log.pas index afc638c..ed4cfe5 100644 --- a/src/engine/e_log.pas +++ b/src/engine/e_log.pas @@ -41,6 +41,10 @@ function DecodeIPV4 (ip: LongWord): string; procedure e_InitWritelnDriver (); procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true); +procedure e_LogWriteln (const s: AnsiString; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true); + + +procedure e_WriteStackTrace (const msg: AnsiString); var @@ -68,54 +72,12 @@ procedure e_WriteLog (TextLine: String; RecordCategory: TRecordCategory; WriteTi begin e_LogWritefln('%s', [TextLine], RecordCategory, WriteTime); end; -(* -var - LogFile: TextFile; - Prefix: ShortString = ''; - OutStr: String; -begin - if driverInited and (length(TextLine) > 0) then - begin - case RecordCategory of - MSG_FATALERROR: write('FATAL: '); - MSG_WARNING: write('WARNING: '); - end; - writeln(TextLine); - end; - if FileName = '' then Exit; - Assign(LogFile, FileName); - try - if FileExists(FileName) then - Append(LogFile) - else - Rewrite(LogFile); - try - if FirstRecord then - begin - Writeln(LogFile, '--- Log started at '+TimeToStr(Time)+' ---'); - FirstRecord := False; - end; - case RecordCategory of - MSG_FATALERROR: Prefix := '!!!'; - MSG_WARNING: Prefix := '! '; - MSG_NOTIFY: Prefix := '***'; - end; - if WriteTime then - OutStr := '['+TimeToStr(Time)+'] '+Prefix+' '+TextLine - else - OutStr := Prefix+' '+TextLine; - Writeln(LogFile, OutStr); - if e_WriteToStdOut then - Writeln(OutStr); - finally - Close(LogFile); - end; - except // sorry - end; +procedure e_LogWriteln (const s: AnsiString; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true); +begin + e_LogWritefln('%s', [s], category, writeTime); end; -*) // returns formatted string if `writerCB` is `nil`, empty string otherwise @@ -281,6 +243,24 @@ begin end; +{$I-} +procedure e_WriteStackTrace (const msg: AnsiString); +var + tfo: TextFile; +begin + e_LogWriteln(msg, MSG_FATALERROR); + if (Length(FileName) > 0) then + begin + if xlogFileOpened then CloseFile(xlogFile); + xlogFileOpened := false; + AssignFile(tfo, FileName); + Append(tfo); + if (IOResult <> 0) then Rewrite(tfo); + if (IOResult = 0) then begin writeln(tfo, '====================='); DumpExceptionBackTrace(tfo); CloseFile(tfo); end; + end; +end; + + procedure e_DeinitLog (); begin if xlogFileOpened then CloseFile(xlogFile);