-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathacLog.pas
75 lines (61 loc) · 1.35 KB
/
acLog.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
unit acLog;
interface
uses
forms, classes;
type
TacLog = class
private
FdirName: string;
FfileName: string;
protected
procedure checkDir;
function getDir: string;
function getFile: string;
public
property dirName: string read FdirName write FdirName;
property fileName: string read FfileName write FfileName;
constructor create;
procedure addLog(str: string);
end;
implementation
uses SysUtils;
{ TacLog }
procedure TacLog.addLog(str: string);
var
strL: TStringList;
begin
checkDir;
strL := TStringList.Create;
try
if FileExists(getDir + getFile) then
strL.LoadFromFile(getDir + getFile);
strL.Add(FormatDateTime('dd/mm/yyyy - hh:nn:ss: ', now) + str);
strL.SaveToFile(getDir + getFile);
finally
FreeAndNil(strL);
end;
end;
procedure TacLog.checkDir;
begin
if not DirectoryExists(getDir) then
CreateDir(getDir);
end;
constructor TacLog.create;
begin
FdirName := '';
end;
function TacLog.getDir: string;
begin
if FdirName='' then
result := ExtractFilePath(Application.ExeName) + 'logs/'
else
result := FdirName;
end;
function TacLog.getFile: string;
begin
if FfileName='' then
result := FormatDateTime('ddmmyy',Date)+'.log'
else
result := FfileName;
end;
end.