delphi 로그 단위

1207 단어 delphi
unit uText;

interface

uses   Windows,SysUtils;

procedure WriteLog(strlog:string;tag:string='CommonMsg');
procedure WriteToConsole(strlog:string;tag:string='CommonMsg');

{$APPTYPE CONSOLE}
implementation
var
LogText: Text;
FileName: string = 'D:\log.txt';

procedure WriteLog(strlog:string;tag:string='CommonMsg');
var
  logMsg:string;
  begin
    try
        AssignFile(LogText,FileName);
        if not FileExists(FileName) then
        begin
           ReWrite(LogText)
        end
        else
            Append(LogText);
        logMsg:=FormatdateTime('yyyy-mm-dd hh:nn:ss', Now)+' '+tag+':'+strlog;
        WriteLn(LogText,logMsg);
    finally
          CloseFile(LogText);
    end;
  end;


procedure WriteToConsole(strlog:string;tag:string='CommonMsg');
var
  logMsg,instr:string;

begin
  logMsg:=FormatdateTime('yyyy-mm-dd hh:nn:ss', Now)+' '+tag+':'+strlog;
  try
    Writeln(logMsg);
  except
    WriteLog('     ','ConError');
  end;
end;

initialization  {        }
  AllocConsole;
  SetConsoleTitle('       ');
finalization    {    }
  FreeConsole;
end.

좋은 웹페이지 즐겨찾기