// TFFLogger is a wrapper of TFFLogWorker

type
  TFFLogger = class(TFFBaseComponent)
  private
    FOnLog: TLogEvent;
    function  GetActive: Boolean;
    procedure SetActive(const Value: Boolean);
    function  GetLogFile: string;
    procedure SetLogFile(const Value: string);
    function  GetLogFlags: Integer;
    procedure SetLogFlags(const Value: Integer);
    function  GetLogLevel: TLogLevel;
    procedure SetLogLevel(const Value: TLogLevel);
    function  GetLogToFile: Boolean;
    procedure SetLogToFile(const Value: Boolean);
    function  GetLogWithLevel: Boolean;
    procedure SetLogWithLevel(const Value: Boolean);
    function  GetLogWithThreadID: Boolean;
    procedure SetLogWithThreadID(const Value: Boolean);
    function  GetLogWithTime: Boolean;
    procedure SetLogWithTime(const Value: Boolean);
    function  GetSynchronous: Boolean;
    procedure SetSynchronous(const Value: Boolean);
    function  GetTriggerEventInMainThread: Boolean;
    procedure SetTriggerEventInMainThread(const Value: Boolean);
    function  GetOnLog: TLogEvent;
    procedure SetOnLog(const Value: TLogEvent);
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    procedure ClearLogFile;
    procedure Log(Sender: TObject; ALogLevel: TLogLevel; const ALogMsg: string); overload;
    procedure Log(Sender: TObject; ALogLevel: TLogLevel; const AFormat: string; const Args: array of const); overload;
    property  LogFlags: Integer read GetLogFlags write SetLogFlags;
  published
    property Active: Boolean read GetActive write SetActive default True;
    property LogFile: string read GetLogFile write SetLogFile;
    property LogLevel: TLogLevel read GetLogLevel write SetLogLevel default llInfo;
    property LogToFile: Boolean read GetLogToFile write SetLogToFile default False;
    property LogWithLevel: Boolean read GetLogWithLevel Write SetLogWithLevel default True;
    property LogWithThreadID: Boolean read GetLogWithThreadID Write SetLogWithThreadID default True;
    property LogWithTime: Boolean read GetLogWithTime Write SetLogWithTime default True;
    property Synchronous: Boolean read GetSynchronous write SetSynchronous default False;
    property TriggerEventInMainThread: Boolean read GetTriggerEventInMainThread write SetTriggerEventInMainThread default True;
    property OnLog: TLogEvent read GetOnLog write SetOnLog;
  end;

function FFLogger: TFFLogWorker; {$IFDEF USE_INLINE}inline;{$ENDIF}

implementation

function FFLogger: TFFLogWorker;
begin
  Result := FFLoad.FFLogger;
end;

{ TFFLogger }

var
  GLoggerCount: Integer = 0;

constructor TFFLogger.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  if not (csDesigning in ComponentState) then
    Assert(GLoggerCount = 0, 'Allow creating only one instance of TFFLogger.');
  Inc(GLoggerCount);
end;

destructor TFFLogger.Destroy;
begin
  Dec(GLoggerCount);
  if Assigned(FFLogger.OnLog) and Assigned(FOnLog) and (Addr(FFLogger.OnLog) = Addr(FOnLog)) then
    FFLogger.OnLog := nil;
  inherited Destroy;
end;

procedure TFFLogger.ClearLogFile;
begin
  FFLogger.ClearLogFile;
end;

procedure TFFLogger.Log(Sender: TObject; ALogLevel: TLogLevel; const ALogMsg: string);
begin
  FFLogger.Log(Sender, ALogLevel, ALogMsg);
end;

procedure TFFLogger.Log(Sender: TObject; ALogLevel: TLogLevel; const AFormat: string; const Args: array of const);
begin
  FFLogger.Log(Sender, ALogLevel, AFormat, Args);
end;

function TFFLogger.GetActive: Boolean;
begin
  Result := FFLogger.Active;
end;

procedure TFFLogger.SetActive(const Value: Boolean);
begin
  FFLogger.Active := Value;
end;

function TFFLogger.GetLogFile: string;
begin
  Result := FFLogger.LogFile;
end;

procedure TFFLogger.SetLogFile(const Value: string);
begin
  FFLogger.LogFile := Value;
end;

function TFFLogger.GetLogFlags: Integer;
begin
  Result := FFLogger.LogFlags;
end;

procedure TFFLogger.SetLogFlags(const Value: Integer);
begin
  FFLogger.LogFlags := Value;
end;

function TFFLogger.GetLogLevel: TLogLevel;
begin
  Result := FFLogger.LogLevel;
end;

procedure TFFLogger.SetLogLevel(const Value: TLogLevel);
begin
  FFLogger.LogLevel := Value;
end;

function TFFLogger.GetLogToFile: Boolean;
begin
  Result := FFLogger.LogToFile;
end;

procedure TFFLogger.SetLogToFile(const Value: Boolean);
begin
  FFLogger.LogToFile := Value;
end;

function TFFLogger.GetLogWithLevel: Boolean;
begin
  Result := FFLogger.LogWithLevel;
end;

procedure TFFLogger.SetLogWithLevel(const Value: Boolean);
begin
  FFLogger.LogWithLevel := Value;
end;

function TFFLogger.GetLogWithTime: Boolean;
begin
  Result := FFLogger.LogWithTime;
end;

procedure TFFLogger.SetLogWithTime(const Value: Boolean);
begin
  FFLogger.LogWithTime := Value;
end;

function TFFLogger.GetLogWithThreadID: Boolean;
begin
  Result := FFLogger.LogWithThreadID;
end;

procedure TFFLogger.SetLogWithThreadID(const Value: Boolean);
begin
  FFLogger.LogWithThreadID := Value;
end;

function TFFLogger.GetSynchronous: Boolean;
begin
  Result := FFLogger.Synchronous;
end;

procedure TFFLogger.SetSynchronous(const Value: Boolean);
begin
  FFLogger.Synchronous := Value;
end;

function TFFLogger.GetTriggerEventInMainThread: Boolean;
begin
  Result := FFLogger.TriggerEventInMainThread;
end;

procedure TFFLogger.SetTriggerEventInMainThread(const Value: Boolean);
begin
  FFLogger.TriggerEventInMainThread := Value;
end;

function TFFLogger.GetOnLog: TLogEvent;
begin
  Result := FFLogger.OnLog;
end;

procedure TFFLogger.SetOnLog(const Value: TLogEvent);
begin
  FFLogger.OnLog := Value;
end;

end.
