X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fengine%2Fe_log.pas;h=8f35d36aa3ba6a54980946a96fda6f9d4983be18;hb=8aa8f3f8069982851df02ee1307a7c01853ac865;hp=ed4cfe525f4479957cca8754c690a99be9f64b4c;hpb=4aae1df7801692bcde3df413028c83edd5c3c655;p=d2df-sdl.git diff --git a/src/engine/e_log.pas b/src/engine/e_log.pas index ed4cfe5..8f35d36 100644 --- a/src/engine/e_log.pas +++ b/src/engine/e_log.pas @@ -1,4 +1,4 @@ -(* Copyright (C) DooM 2D:Forever Developers +(* Copyright (C) Doom 2D: Forever Developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ uses type TWriteMode = (WM_NEWFILE, WM_OLDFILE); - TRecordCategory = (MSG_FATALERROR, MSG_WARNING, MSG_NOTIFY); + TMsgType = (Fatal, Warning, Notify); procedure e_InitLog (fFileName: String; fWriteMode: TWriteMode); @@ -33,15 +33,15 @@ procedure e_DeinitLog (); procedure e_SetSafeSlowLog (slowAndSafe: Boolean); -procedure e_WriteLog (TextLine: String; RecordCategory: TRecordCategory; WriteTime: Boolean=True); +procedure e_WriteLog (TextLine: String; RecordCategory: TMsgType; WriteTime: Boolean=True); function DecodeIPV4 (ip: LongWord): string; // start Write/WriteLn driver. it will write everything to cbuf. 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_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true); +procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true); procedure e_WriteStackTrace (const msg: AnsiString); @@ -54,6 +54,7 @@ var implementation uses + {SDL2,} conbuf, utils; var @@ -68,15 +69,24 @@ begin end; -procedure e_WriteLog (TextLine: String; RecordCategory: TRecordCategory; WriteTime: Boolean=True); +function consoleAllow (const s: String): Boolean; begin - e_LogWritefln('%s', [TextLine], RecordCategory, WriteTime); + Result := False; + if Pos('[Chat] ', s) = 1 then + Exit; + Result := True; end; -procedure e_LogWriteln (const s: AnsiString; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true); +procedure e_WriteLog (TextLine: String; RecordCategory: TMsgType; WriteTime: Boolean=True); begin - e_LogWritefln('%s', [s], category, writeTime); + e_LogWritefln('%s', [TextLine], RecordCategory, WriteTime, consoleAllow(TextLine)); +end; + + +procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true); +begin + e_LogWritefln('%s', [s], category, writeTime, consoleAllow(s)); end; @@ -89,9 +99,22 @@ var ss: ShortString; slen: Integer; b: PByte; +{$IFDEF ANDROID} + cstr: PChar; +{$ENDIF} begin if (len < 1) then exit; b := PByte(@buf); + +{$IFDEF ANDROID} + cstr := GetMem(len + 1); + for slen := 0 to len - 1 do + cstr[slen] := Chr(b[slen]); + cstr[len] := #0; + SDL_Log(cstr, []); + Dispose(cstr); +{$ENDIF} + while (len > 0) do begin if (len > 255) then slen := 255 else slen := Integer(len); @@ -167,7 +190,7 @@ begin end; -procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true); +procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true); procedure xwrite (const s: AnsiString); begin @@ -176,11 +199,11 @@ procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: end; begin - if driverInited and (length(fmt) > 0) then + if driverInited and (length(fmt) > 0) and writeConsole then begin case category of - MSG_FATALERROR: write('FATAL: '); - MSG_WARNING: write('WARNING: '); + TMsgType.Fatal: write('FATAL: '); + TMsgType.Warning: write('WARNING: '); end; formatstrf(fmt, args, conwriter); writeln; @@ -208,9 +231,9 @@ begin xlogPrefix := ''; if writeTime then begin xlogPrefix += '['; xlogPrefix += TimeToStr(Time); xlogPrefix += '] '; end; case category of - MSG_FATALERROR: xlogPrefix += '!!!'; - MSG_WARNING: xlogPrefix += '! '; - MSG_NOTIFY: xlogPrefix += '***'; + TMsgType.Fatal: xlogPrefix += '!!!'; + TMsgType.Warning: xlogPrefix += '! '; + TMsgType.Notify: xlogPrefix += '***'; end; xlogLastWasEOL := true; // to output prefix xlogWantSpace := true; // after prefix @@ -232,7 +255,7 @@ begin if xlogFileOpened then CloseFile(xlogFile); xlogFileOpened := false; FileName := fFileName; - if (fWriteMode = WM_NEWFILE) then + if (fWriteMode = TWriteMode.WM_NEWFILE) then begin try if FileExists(FileName) then DeleteFile(FileName); @@ -248,7 +271,7 @@ procedure e_WriteStackTrace (const msg: AnsiString); var tfo: TextFile; begin - e_LogWriteln(msg, MSG_FATALERROR); + e_LogWriteln(msg, TMsgType.Fatal); if (Length(FileName) > 0) then begin if xlogFileOpened then CloseFile(xlogFile);