TPDFlibLogger

Data types, document management

Description

TPDFlibLogger is the structured logger class attached to a TPDFlib instance through its Logger property. When assigned, it receives Debug, Info, Warn and Error records, each carrying a numeric code drawn from the existing LastErrorCode taxonomy and a human-readable message

The logger is caller-owned and may be shared across several TPDFlib instances. It is nil by default, so the no-logger path is zero-cost

Syntax

Delphi

TPDFlibLogger = Class
  Public
    Constructor Create; Virtual;
    Destructor Destroy; Override;
    Procedure Log(Level: TPDFlibLogLevel; Code: Integer; Const Msg: WideString); Overload;
    Procedure Log(Level: TPDFlibLogLevel; Code: Integer; Const Msg: WideString;
      Const ExtraFieldsText: WideString); Overload;
    Procedure Debug(Code: Integer; Const Msg: WideString);
    Procedure Info(Code: Integer; Const Msg: WideString);
    Procedure Warn(Code: Integer; Const Msg: WideString);
    Procedure Error_(Code: Integer; Const Msg: WideString);
    Property Level: TPDFlibLogLevel Read FLevel Write FLevel;
    Property OnLog: TPDFlibLogEvent Read FOnLog Write FOnLog;
    Property FileName: WideString Read FFileName Write SetFileName;
  End;

Properties

LevelThe minimum severity to emit; records below this threshold are silently dropped
OnLogA host callback invoked for every emitted record, receiving the level, code and message
FileNameWhen set, records are also written to this file through a thread-safe TStreamWriter sink; clear it to stop file logging

Remarks

The convenience methods Debug, Info, Warn and Error_ call Log with the matching level

File writes are serialized with a critical section, so a single logger instance is safe to use from worker threads

PDFlibErrorMessage(Code) translates a numeric code into a human message and can be called independently of the logger

See also

Logger, OnOperationProgress, LastErrorCode