-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsLogging.pas
60 lines (45 loc) · 1.57 KB
/
clsLogging.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
unit clsLogging;
interface
uses
System.SysUtils,System.Classes, Winapi.Windows;
type
TLog = class(TObject)
private
//sLogType,sLogInput : string;
fLogFile : TextFile;
public
constructor Create;
procedure WriteLog(sLogType:string;sLogInput:string);
end;
implementation
// This is for when we create the Logging object. This will be used when a section
// of the application is suppose to log an action that is being preformed
// The function will check if a log file exist and open it. If one does not exist
// It will create a log file with today's date and append the .log for the file type
constructor TLog.Create();
begin
AssignFile(fLogFile, GetEnvironmentVariable('appdata') + '/POS 2.0/LOGS/' +
FormatDateTime('dd-mm-yyyy',Now) + '.log');
if FileExists( GetEnvironmentVariable('appdata') + '/POS 2.0/LOGS/' +
FormatDateTime('dd-mm-yyyy',Now) + '.log') = False then
begin
Rewrite(fLogFile);
Close(fLogFile);
end ;
Append(fLogFile);
end;
// Section of the application will call this function when it is ready to write
// and action to the log file. The function should be called after the create function
// as it will need the log file to write to. In the application when you call this function
// You should say whether the type of log is info , debug or an error. Then you sould
// Passthough your log message.
procedure TLog.WriteLog(sLogType:string;sLogInput:string);
begin
try
Append(fLogFile);
Writeln(fLogFile,'['+TimeToStr(Now)+']['+sLogType+']'+sLogInput);
CloseFile(fLogFile);
except
end;
end;
end.