|
@@ -0,0 +1,60 @@
|
|
|
+unit LogUtils;
|
|
|
+
|
|
|
+interface
|
|
|
+
|
|
|
+uses
|
|
|
+ Classes;
|
|
|
+
|
|
|
+type
|
|
|
+ TLogUtils = class
|
|
|
+ private
|
|
|
+ FLogFolder: string;
|
|
|
+ FLogFile: string;
|
|
|
+ public
|
|
|
+ constructor Create;
|
|
|
+ destructor Destroy; override;
|
|
|
+
|
|
|
+ procedure AppendLogTo(const ALog: string);
|
|
|
+ end;
|
|
|
+
|
|
|
+implementation
|
|
|
+
|
|
|
+uses SysUtils, UtilMethods, Math, ZhAPI;
|
|
|
+
|
|
|
+{ TLog }
|
|
|
+
|
|
|
+procedure TLogUtils.AppendLogTo(const ALog: string);
|
|
|
+var
|
|
|
+ f: TextFile;
|
|
|
+begin
|
|
|
+ try
|
|
|
+ AssignFile(f, FLogFile);
|
|
|
+ if FileExists(FLogFile) then
|
|
|
+ Append(f)
|
|
|
+ else
|
|
|
+ Rewrite(f);
|
|
|
+ Writeln(f, Format('%s %s', [DateTimeToStr(Now), ALog]));
|
|
|
+ Flush(f);
|
|
|
+ finally
|
|
|
+ CloseFile(f);
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+constructor TLogUtils.Create;
|
|
|
+var
|
|
|
+ vFormatSetting: TFormatSettings;
|
|
|
+begin
|
|
|
+ vFormatSetting.ShortDateFormat := 'yyyy/MM/dd';
|
|
|
+ vFormatSetting.DateSeparator := '-';
|
|
|
+ FLogFolder := GetAppFilePath + 'log';
|
|
|
+ if not DirectoryExists(FLogFolder) then
|
|
|
+ CreateDirectoryInDeep(FLogFolder);
|
|
|
+ FLogFile := FLogFolder + '\' + DateToStr(Date, vFormatSetting) + '.log';
|
|
|
+end;
|
|
|
+
|
|
|
+destructor TLogUtils.Destroy;
|
|
|
+begin
|
|
|
+ inherited;
|
|
|
+end;
|
|
|
+
|
|
|
+end.
|