From: Ketmar Dark Date: Fri, 15 Apr 2016 11:51:36 +0000 (+0300) Subject: do not fail on log writing errors X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=5d49aa6a925e49d43993305b3e4071fd70286a90;p=d2df-sdl.git do not fail on log writing errors --- diff --git a/src/engine/e_log.pas b/src/engine/e_log.pas index b877db3..d45f86e 100644 --- a/src/engine/e_log.pas +++ b/src/engine/e_log.pas @@ -1,3 +1,4 @@ +{$R-} unit e_log; interface @@ -36,25 +37,31 @@ begin if FileName = '' then Exit; Assign(LogFile, FileName); - if FileExists(FileName) then - Append(LogFile) - else - Rewrite(LogFile); - 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 := '***'; + 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 + Writeln(LogFile, '['+TimeToStr(Time)+'] '+Prefix+' '+TextLine) + else + Writeln(LogFile, Prefix+' '+TextLine); + finally + Close(LogFile); + end; + except // sorry end; - if WriteTime then - Writeln(LogFile, '['+TimeToStr(Time)+'] '+Prefix+' '+TextLine) - else - Writeln(LogFile, Prefix+' '+TextLine); - Close(LogFile); end; procedure e_InitLog(fFileName: String; fWriteMode: TWriteMode);