Selaa lähdekoodia

Merge branch 'SignOnline' of http://192.168.1.12:3000/maixinrong/measure into SignOnline

MaiXinRong 8 vuotta sitten
vanhempi
commit
65c38adb8a
1 muutettua tiedostoa jossa 60 lisäystä ja 0 poistoa
  1. 60 0
      Units/LogUtils.pas

+ 60 - 0
Units/LogUtils.pas

@@ -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.