//写入与LED交互的日志,和LED显示屏的交互日志
procedure WriteLogled(const sTxt: string; AisLog:Boolean=True; AFileName: string=''); //写Log文件 AisLog:是否记录log, 可引用全局的 GIsLog
var
sFilename: string;
LogFile: TextFile;
begin
if not AisLog then exit;
Lockcs.Lock;
try
sFilename := ExtractFilePath(Application.ExeName) + 'Log\';
if not DirectoryExists(sFilename) then
if not CreateDir(sFilename) then
exit;
if AFileName<>'' then
sFilename := sFilename +AFileName+FormatDateTime('YYYYMMDD', Date())+'.LOG'
else
sFilename := sFilename + ChangeFileExt(ExtractFileName(Application.ExeName) ,'') + FormatDateTime('YYYYMMDD', Date())+'.LOG';
try
Assignfile(LogFile, sFilename);
if FileExists(sFilename) then
Append(LogFile)
else
ReWrite(LogFile);
Writeln(LogFile, FormatDateTime('YYYY-MM-DD HH:MM:ss.zzz',now) + ':' + sTxt);
Flush(LogFile);// 用于清空文件的缓冲区。这个过程保证了缓冲区的中的所有字符都已经写入外部文件中。对于因为输入而打开的文件,Flush函数不起任何作用。
finally
try
CloseFile(LogFile);
except
end;
Lockcs.UnLock;
end;
except
WriteLogErr(sTxt);
end;
end;
//写入与LED交互的日志,和LED显示屏的交互日志
procedure WriteLogled(const sTxt: string; AisLog:Boolean=True; AFileName: string=''); //写Log文件 AisLog:是否记录log, 可引用全局的 GIsLog
var
sFilename: string;
LogFile: TextFile;
begin
if not AisLog then exit;
Lockcs.Lock;
try
sFilename := ExtractFilePath(Application.ExeName) + 'Log\';
if not DirectoryExists(sFilename) then
if not CreateDir(sFilename) then
exit;
if AFileName<>'' then
sFilename := sFilename +AFileName+FormatDateTime('YYYYMMDD', Date())+'.LOG'
else
sFilename := sFilename + ChangeFileExt(ExtractFileName(Application.ExeName) ,'') + FormatDateTime('YYYYMMDD', Date())+'.LOG';
try
Assignfile(LogFile, sFilename);
if FileExists(sFilename) then
Append(LogFile)
else
ReWrite(LogFile);
Writeln(LogFile, FormatDateTime('YYYY-MM-DD HH:MM:ss.zzz',now) + ':' + sTxt);
Flush(LogFile);// 用于清空文件的缓冲区。这个过程保证了缓冲区的中的所有字符都已经写入外部文件中。对于因为输入而打开的文件,Flush函数不起任何作用。
finally
try
CloseFile(LogFile);
except
end;
Lockcs.UnLock;
end;
except
WriteLogErr(sTxt);
end;
end;
//写入与LED交互的日志,和LED显示屏的交互日志