From 7d5854863648d8064a3daa3fd64c8c9b2d1597a7 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Thu, 24 Aug 2017 18:58:38 +0300 Subject: [PATCH] added "--safe-log" cli arg: log writer will be slower, but should not loose log entries on crash --- src/engine/e_log.pas | 21 +++++++++++++++++++++ src/game/Doom2DF.dpr | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/engine/e_log.pas b/src/engine/e_log.pas index 523c27f..aba6e0d 100644 --- a/src/engine/e_log.pas +++ b/src/engine/e_log.pas @@ -31,6 +31,8 @@ type procedure e_InitLog (fFileName: String; fWriteMode: TWriteMode); procedure e_DeinitLog (); +procedure e_SetSafeSlowLog (slowAndSafe: Boolean); + procedure e_WriteLog (TextLine: String; RecordCategory: TRecordCategory; WriteTime: Boolean=True); function DecodeIPV4 (ip: LongWord): string; @@ -146,6 +148,19 @@ var xlogPrefix: AnsiString; xlogLastWasEOL: Boolean = false; xlogWantSpace: Boolean = false; + xlogSlowAndSafe: Boolean = false; + + +procedure e_SetSafeSlowLog (slowAndSafe: Boolean); +begin + xlogSlowAndSafe := slowAndSafe; + if xlogSlowAndSafe and xlogFileOpened then + begin + CloseFile(xlogFile); + xlogFileOpened := false; + end; +end; + procedure logwriter (constref buf; len: SizeUInt); var @@ -247,6 +262,12 @@ begin formatstrf(fmt, args, logwriter); if not xlogLastWasEOL then writeln(xlogFile, '') else writeln(xlogFile, xlogPrefix); + if xlogSlowAndSafe and xlogFileOpened then + begin + CloseFile(xlogFile); + xlogFileOpened := false; + end; + //if fopened then CloseFile(xlogFile); end; diff --git a/src/game/Doom2DF.dpr b/src/game/Doom2DF.dpr index de39e51..1276f72 100644 --- a/src/game/Doom2DF.dpr +++ b/src/game/Doom2DF.dpr @@ -120,7 +120,8 @@ begin for f := 1 to ParamCount do begin if ParamStr(f) = '--gdb' then noct := true - else if ParamStr(f) = '--log' then conbufDumpToStdOut := true; + else if ParamStr(f) = '--log' then conbufDumpToStdOut := true + else if ParamStr(f) = '--safe-log' then e_SetSafeSlowLog(true); end; if noct then begin -- 2.29.2