DEADSOFTWARE

ambient light for level (doesn't work with dynamic lights; I. WANT. SHADERS!)
[d2df-sdl.git] / src / engine / e_log.pas
index afc638cac7be82a9d7af6a0f1eb764811adf4eb8..ed4cfe525f4479957cca8754c690a99be9f64b4c 100644 (file)
@@ -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);