DEADSOFTWARE

e82bfb41149a0533db9173023bafbfe3cce249d2
[d2df-sdl.git] / src / engine / e_log.pas
1 {$R-}
2 unit e_log;
4 interface
6 uses
7 SysUtils;
9 type
10 TWriteMode=(WM_NEWFILE, WM_OLDFILE);
11 TRecordCategory=(MSG_FATALERROR, MSG_WARNING, MSG_NOTIFY);
13 procedure e_InitLog(fFileName: String; fWriteMode: TWriteMode);
14 procedure e_WriteLog(TextLine: String; RecordCategory: TRecordCategory;
15 WriteTime: Boolean = True);
16 function DecodeIPV4(ip: LongWord): string;
18 implementation
20 var
21 FirstRecord: Boolean;
22 FileName: String;
24 { TLog }
26 function DecodeIPV4(ip: LongWord): string;
27 begin
28 Result := Format('%d.%d.%d.%d', [ip and $FF, (ip shr 8) and $FF, (ip shr 16) and $FF, (ip shr 24)]);
29 end;
31 procedure e_WriteLog(TextLine: String; RecordCategory: TRecordCategory;
32 WriteTime: Boolean = True);
33 var
34 LogFile: TextFile;
35 Prefix: ShortString = '';
36 begin
37 if FileName = '' then Exit;
39 Assign(LogFile, FileName);
40 try
41 if FileExists(FileName) then
42 Append(LogFile)
43 else
44 Rewrite(LogFile);
45 try
46 if FirstRecord then
47 begin
48 Writeln(LogFile, '--- Log started at '+TimeToStr(Time)+' ---');
49 FirstRecord := False;
50 end;
51 case RecordCategory of
52 MSG_FATALERROR: Prefix := '!!!';
53 MSG_WARNING: Prefix := '! ';
54 MSG_NOTIFY: Prefix := '***';
55 end;
56 if WriteTime then
57 Writeln(LogFile, '['+TimeToStr(Time)+'] '+Prefix+' '+TextLine)
58 else
59 Writeln(LogFile, Prefix+' '+TextLine);
60 finally
61 Close(LogFile);
62 end;
63 except // sorry
64 end;
65 end;
67 procedure e_InitLog(fFileName: String; fWriteMode: TWriteMode);
68 begin
69 FileName := fFileName;
70 if fWriteMode = WM_NEWFILE then
71 begin
72 try
73 if FileExists(FileName) then DeleteFile(FileName);
74 except // sorry
75 end;
76 end;
77 FirstRecord := True;
78 end;
80 end.