unit Sparkle.Logger;

{$I Sparkle.Inc}

interface

type
  ILogEngine = interface
    {$IFDEF DEBUGLOG}
    procedure Enter(const Msg: string);
    procedure Leave(const Msg: string);
    {$ENDIF}
    procedure Log(const Msg: string);
  end;

  TLogger = class
  strict private
    FLogEngine: ILogEngine;
  public
    procedure Log(const Msg: string);
    {$IFDEF DEBUGLOG}
    procedure Enter(const Msg: string);
    procedure Leave(const Msg: string);
    procedure Debug(const Msg: string);
    {$ENDIF}
    property LogEngine: ILogEngine read FLogEngine write FLogEngine;
  end;

implementation

{ TLogger }

{$IFDEF DEBUGLOG}
procedure TLogger.Enter(const Msg: string);
begin
  if FLogEngine <> nil then
    FLogEngine.Enter(Msg);
end;
{$ENDIF}

{$IFDEF DEBUGLOG}
procedure TLogger.Leave(const Msg: string);
begin
  if FLogEngine <> nil then
    FLogEngine.Leave(Msg);
end;
{$ENDIF}

procedure TLogger.Log(const Msg: string);
begin
  if FLogEngine <> nil then
    FLogEngine.Log(Msg);
end;

{$IFDEF DEBUGLOG}
procedure TLogger.Debug(const Msg: string);
begin
  if FLogEngine <> nil then
    FLogEngine.Log(Msg);
end;
{$ENDIF}

end.
