procedure TfrmMain.WriteLog(str: string);
var
F:textfile;
filename: string;
begin
if trim(str)<>'' then
try
filename := exepath+FormatDateTime('yyyy-mm-dd',now)+'.log';
assignfile(f,filename);
if FileExists(filename) then reset(f) else rewrite(F);
append(f);
writeln(f,trim(str)+'->'+FormatDateTime('HH:MM:SS',now));
flush(f);
finally
closefile(f);
end;
end;
procedure WriteLog(strLog:string;ModLevel,SysLogLevel:integer);
var
outFile:TextFile;
i:integer;
sLog:string[128];
acLog:array[0..159] of char;
sLogFile:string;
bNewFile:boolean;
begin
if ModLevel>SysLogLevel then exit;
for i:=ModLevel-1 downto 0 do begin //Indent
sLog:=Format('%s%s',[' ',sLog]);
end;
sLog:=FormatDateTime('YYYY-MM-DD HH:MM:SS:zzz',Now)+#9+strLog;
if length(sLog)>158 then sLog:=copy(sLog,1,158);
fillMemory(@acLog,160,ord(' '));
for i:=0 to length(sLog)-1 do begin
acLog[i]:=sLog[i+1];
end;
sLogFile:='Log\SmartUp_'+formatdatetime('MMDD',Now)+'.log';
bNewFile:= FileExists(sLogFile);
AssignFile(outFile,sLogFile);
if Not bNewFile then ReWrite(outFile)
else Append(outFile);
procedure LogToFile(astr: string; fn: string = 'AppLog');
var
f: TextFile;
begin
astr := formatdatetime('yy/mm/dd HH:nn', now) + ':'+ astr;
if fn = 'AppLog' then
fn := ChangeFileExt(GetModuleName(HInstance), '.' + formatdatetime('yymmdd', now) + '.log.txt');
AssignFile(f, fn);
try
if FileExists(fn) then
Append(f)
else Rewrite(f);
Writeln(f, astr);
{ insert code here that would require a Flush before closing the file }
Flush(f); { ensures that the text was actually written to file }
finally
CloseFile(f);
end;
end;