Classe TFilesLogs

Unit

Declaração

type TFilesLogs = class(TObjectsConsts)

Descrição

Hierarquia

Visão Geral

Tipos Aninhados

Public TLogType = eventlog.TLogType;

Campos

Public nested const EnableWriteIdentificao : Boolean = true;

Métodos

Public constructor Create(aowner:TComponent); Override; Overload;
Public destructor destroy; override;
Public procedure Warning( const Fmt: string;Args: array of Const); overload;
Public procedure Warning( const Msg: string ); overload;
Public procedure Error(const Fmt: String; Args: array of const); overload;
Public procedure Error(const Msg: String); overload;
Public procedure Info(const Fmt: String; Args: array of const); overload;
Public procedure Info(const Msg: String); overload;
Public Function _Write(Const S : AnsiString;Ln:Boolean):SmallInt;
Public Function Flush_WiteBuffer:Boolean;
Public Function WriteFErr_Ln_On_Off(Const S : AnsiString;aLn_On_Off:Boolean):SmallInt;
Public Function WriteFErr(Const S : AnsiString):SmallInt;
Public Function WriteLnFErr(Const S : AnsiString):SmallInt;
Public Procedure WriteIdentificao;
Public PROCEDURE LogError(const Fmt: String; Args: array of const); overload;
Public PROCEDURE LogError(CONST Msg:AnsiString ); overload;

Propriedades

Published property fileLog : TEventLog Read _fileLog;
Public property FileName : string read GetFileName write SetFileName;
Public property Active : Boolean Read GetActive write SetActive;
Public property LogType : TLogType Read GetLogtype Write SetlogType;
Public property AppendContent : Boolean Read GetAppendContent Write SetAppendContent;
Public property RaiseExceptionOnError : Boolean Read GetRaiseExceptionOnError Write SetRaiseExceptionOnError;

Descrição

Tipos Aninhados

Public TLogType = eventlog.TLogType;

  • O tipo TLogType é usado pra direcionar o destino das mensagens de log.

    • TLogType

      • ltSystem : Envia as mensagens de log para /var/syslog no linux ou o arquivo de log do sistema operacional.

        • Obs: O windows não tem esse arquivo de log padrão, por isso não funciona na plataforma windows.

      • ltFile : Envia as mensagens de log para NomeDoArquivo.log definido por FileName.

      • ltStdOut : Envia as mensagens de log para o monitor de vídeo.

      • ltStdErr : Envia as mensagens de log para o monitor de vídeo.

Campos

Public nested const EnableWriteIdentificao : Boolean = true;
 

Métodos

Public constructor Create(aowner:TComponent); Override; Overload;

O constructor Create cria uma instância da classe TFilesLogs e inicializa as propriedade FileName := ParamStr(0)+'.log', LogType := ltFile, RaiseExceptionOnError := true, AppendContent := true e active := true.

Public destructor destroy; override;
 
Public procedure Warning( const Fmt: string;Args: array of Const); overload;

Public procedure Warning( const Msg: string ); overload;

  • A procedure Warning é usada registrar mensagens do tipo etWarning.

    • PARÂMETROS

      • Msg : String com a mensagem de atenção.

    • REFERÊNCIA

    • EXEMPLO:

      
      procedure TMi_Rtl_Tests.Button2Click(Sender: TObject);
      begin
        with Tobjectss do
          if Logs.Active then
          with Logs do
          begin
            Warning('Senha inválida!');
          end;
      end;

      • Arquivo de logs: rtl.log:

        • [2021-12-09 14:58:00.588 Warning] Senha inválida

Public procedure Error(const Fmt: String; Args: array of const); overload;

  • A procedure Error é usada registrar mensagens do tipo etError.

Public procedure Error(const Msg: String); overload;

  • A procedure Error é usada registrar mensagens do tipo etError.

    • PARÂMETROS

      • Msg : String com o nome do erro.

    • REFERÊNCIA

    • EXEMPLO:

      
      procedure TMi_Rtl_Tests.Button2Click(Sender: TObject);
      begin
        with TObjectss do
          if Logs.Active then
          with Logs do
          begin
            Error('Acesso ao arquivo negado.' );
          end;
      end;

      • Arquivo de logs: rtl.log:

        • [2021-12-09 10:25:41.425 Error] Acesso ao arquivo negado.

Public procedure Info(const Fmt: String; Args: array of const); overload;

Public procedure Info(const Msg: String); overload;

  • A procedure Info é usada registrar mensagens do tipo etInfo.

    • PARÂMETROS

      • Msg : String com mensagem informativa.

    • REFERÊNCIA

    • EXEMPLO:

      
      procedure TMi_Rtl_Tests.Action_Test_Logs_InfoExecute(Sender: TObject);
      begin
        with Tobjectss do
          if Logs.Active then
          with Logs do
          begin
            info('Sistema abortou de forma inesperada.' );
          end;
      end;

      • Arquivo de logs: rtl.log:

        • [2021-12-13 20:46:32.745 Info] Sistema abortou de forma inesperada.

Public Function _Write(Const S : AnsiString;Ln:Boolean):SmallInt;
 
Public Function Flush_WiteBuffer:Boolean;
 
Public Function WriteFErr_Ln_On_Off(Const S : AnsiString;aLn_On_Off:Boolean):SmallInt;
 
Public Function WriteFErr(Const S : AnsiString):SmallInt;
 
Public Function WriteLnFErr(Const S : AnsiString):SmallInt;
 
Public Procedure WriteIdentificao;
 
Public PROCEDURE LogError(const Fmt: String; Args: array of const); overload;
 
Public PROCEDURE LogError(CONST Msg:AnsiString ); overload;
 

Propriedades

Published property fileLog : TEventLog Read _fileLog;
 
Public property FileName : string read GetFileName write SetFileName;

A propriedade FileName armazena o nome do arquivo de log necessário quando a propriedade LogType=ltFile

Public property Active : Boolean Read GetActive write SetActive;

A propriedade Active ativa e desativa a gravação de mensagens no arquivo de log.

Public property LogType : TLogType Read GetLogtype Write SetlogType;

  • A propriedade LogType redireciona o destino das mensagens de log.

    • Veja o tipo TLogType para mais informações.

Public property AppendContent : Boolean Read GetAppendContent Write SetAppendContent;

  • A propriedade AppendContent é usada para indicar ao sistema que o arquivo de log deve ser único ou acumulativo

    • PARÂMETROS

      • True : A abertura do arquivo de log é aberto com o comando append

      • False : A abertura do arquivo de log é aberto com o comando rewrite

      • Código usado na abertura do arquivo

        
        if AppendContent and FileExists(FileName) then
           FileFlags := fmOpenWrite
        else
           FileFlags := fmCreate;

Public property RaiseExceptionOnError : Boolean Read GetRaiseExceptionOnError Write SetRaiseExceptionOnError;

  • A propriedade RaiseExceptionOnError informa ao sistema se deve gerar exceções quando houver erro ao gravar o log.

    • Exemplo de uso de RaiseExceptionOnError

      
      procedure TEventLog.WriteFileLog(EventType : TEventType; const Msg : String);
        Var
          S : String;
      begin
        S:=FormatLogMessage(EventType, Msg)+LineEnding;
        try
          FStream.WriteBuffer(S[1],Length(S));
          S:='';
        except
          On E : Exception do
             S:=E.Message;
          end;
      
        If (S<>'') and RaiseExceptionOnError 
        then  Raise ELogError.CreateFmt(SErrLogFailedMsg,[S]);
      
      end;


Gerado por PasDoc 0.16.0.