X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fengine%2Fe_log.pas;h=0dcb0986b57df31edeef14c6a45b778012daa197;hb=fbb649f409620a55ae48f1bffd655c5a04489371;hp=8ffb75d0d852147ac6cc227e63ceded7cc7123a0;hpb=92b319e1feed5079e42c779aa49b12ffa8672f54;p=d2df-sdl.git diff --git a/src/engine/e_log.pas b/src/engine/e_log.pas index 8ffb75d..0dcb098 100644 --- a/src/engine/e_log.pas +++ b/src/engine/e_log.pas @@ -2,8 +2,7 @@ * * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * the Free Software Foundation, version 3 of the License ONLY. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,13 +19,14 @@ unit e_log; interface -uses - SysUtils; + uses SysUtils; -type - TWriteMode = (WM_NEWFILE, WM_OLDFILE); - TMsgType = (Fatal, Warning, Notify); + type + TWriteMode = (WM_NEWFILE, WM_OLDFILE); + TMsgType = (Fatal, Warning, Notify); + procedure e_Log_Initialize; + procedure e_Log_Finalize; procedure e_InitLog (fFileName: String; fWriteMode: TWriteMode); procedure e_DeinitLog (); @@ -40,21 +40,18 @@ 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: TMsgType=TMsgType.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); - -var - e_WriteToStdOut: Boolean = False; - - implementation uses - SDL2, conbuf, utils; + {$IFDEF ANDROID} + SDL2, + {$ENDIF} + conbuf, utils; var FirstRecord: Boolean; @@ -62,21 +59,40 @@ var driverInited: Boolean = false; + procedure e_Log_Initialize; + begin + end; + + procedure e_Log_Finalize; + begin + e_DeinitLog + end; + + function DecodeIPV4 (ip: LongWord): string; begin Result := Format('%d.%d.%d.%d', [ip and $FF, (ip shr 8) and $FF, (ip shr 16) and $FF, (ip shr 24)]); end; +function consoleAllow (const s: String): Boolean; +begin + Result := False; + if Pos('[Chat] ', s) = 1 then + Exit; + Result := True; +end; + + procedure e_WriteLog (TextLine: String; RecordCategory: TMsgType; WriteTime: Boolean=True); begin - e_LogWritefln('%s', [TextLine], RecordCategory, 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); + e_LogWritefln('%s', [s], category, writeTime, consoleAllow(s)); end; @@ -89,7 +105,9 @@ var ss: ShortString; slen: Integer; b: PByte; +{$IFDEF ANDROID} cstr: PChar; +{$ENDIF} begin if (len < 1) then exit; b := PByte(@buf); @@ -97,11 +115,11 @@ begin {$IFDEF ANDROID} cstr := GetMem(len + 1); for slen := 0 to len - 1 do - cstr[slen] := Char(b[slen]); - cstr[slen + 1] := #0; + cstr[slen] := Chr(b[slen]); + cstr[len] := #0; SDL_Log(cstr, []); Dispose(cstr); -{$ENDIF ANDROID} +{$ENDIF} while (len > 0) do begin @@ -178,7 +196,7 @@ begin end; -procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.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 @@ -187,7 +205,7 @@ 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 TMsgType.Fatal: write('FATAL: ');