DEADSOFTWARE

fixed wadeditor; added nosound mode; fixed codepage problems; fixed pointers; cleanup
[d2df-editor.git] / src / engine / e_log.pas
1 unit e_log;
3 {$INCLUDE ../shared/a_modes.inc}
5 interface
7 uses
8 SysUtils;
10 type
11 TWriteMode=(WM_NEWFILE, WM_OLDFILE);
12 TRecordCategory=(MSG_FATALERROR, MSG_WARNING, MSG_NOTIFY);
14 procedure e_InitLog(fFileName: String; fWriteMode: TWriteMode);
15 procedure e_WriteLog(TextLine: String; RecordCategory: TRecordCategory;
16 WriteTime: Boolean = True);
17 function DecodeIPV4(ip: LongWord): string;
19 implementation
21 var
22 FirstRecord: Boolean;
23 FileName: String;
25 { TLog }
27 function DecodeIPV4(ip: LongWord): string;
28 begin
29 Result := Format('%d.%d.%d.%d', [ip and $FF, (ip shr 8) and $FF, (ip shr 16) and $FF, (ip shr 24)]);
30 end;
32 procedure e_WriteLog(TextLine: String; RecordCategory: TRecordCategory;
33 WriteTime: Boolean = True);
34 var
35 LogFile: TextFile;
36 Prefix: ShortString;
37 begin
38 if FileName = '' then Exit;
40 Assign(LogFile, FileName);
41 if FileExists(FileName) then
42 Append(LogFile)
43 else
44 Rewrite(LogFile);
45 if FirstRecord then
46 begin
47 Writeln(LogFile, '--- Log started at '+TimeToStr(Time)+' ---');
48 FirstRecord := False;
49 end;
50 case RecordCategory of
51 MSG_FATALERROR: Prefix := '!!!';
52 MSG_WARNING: Prefix := '! ';
53 MSG_NOTIFY: Prefix := '***';
54 end;
55 if WriteTime then
56 Writeln(LogFile, '['+TimeToStr(Time)+'] '+Prefix+' '+TextLine)
57 else
58 Writeln(LogFile, Prefix+' '+TextLine);
59 Close(LogFile);
60 end;
62 procedure e_InitLog(fFileName: String; fWriteMode: TWriteMode);
63 begin
64 FileName := fFileName;
65 if fWriteMode = WM_NEWFILE then
66 if FileExists(FileName) then
67 DeleteFile(FileName);
68 FirstRecord := True;
69 end;
71 end.