DEADSOFTWARE

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