unit LogFilter;
interface
uses
  SysUtils, DBXPlatform, DBXTransport;

type
  TLogFilter = class(TTransportFilter)
  public
    constructor Create; override;
    destructor Destroy; override;
    function ProcessInput(const Data: TBytes): TBytes; override;
    function ProcessOutput(const Data: TBytes): TBytes; override;
    function Id: UnicodeString; override;
  end;

const
  LogFilterName = 'Log';

implementation
uses
  CodeSiteLogging;

constructor TLogFilter.Create;
begin
  inherited Create;
  CodeSite.Send(csmBlue,'TLogFilter.Create');
end;

destructor TLogFilter.Destroy;
begin
  CodeSite.Send(csmBlue,'TLogFilter.Destroy');
  inherited Destroy;
end;

function TLogFilter.ProcessInput(const Data: TBytes): TBytes;
begin
  Result := Data; // log incoming data
  CodeSite.Send(csmYellow, 'ProcessInput ' + IntToStr(Length(Data)),
    TEncoding.ASCII.GetString(Data));
end;

function TLogFilter.ProcessOutput(const Data: TBytes): TBytes;
begin
  Result := Data; // log outgoing data
  CodeSite.Send(csmOrange, 'ProcessOutput ' + IntToStr(Length(Data)),
    TEncoding.ASCII.GetString(Data));
end;

function TLogFilter.Id: UnicodeString;
begin
  Result := LogFilterName;
end;

initialization
  TTransportFilterFactory.RegisterFilter(LogFilterName, TLogFilter);
finalization
  TTransportFilterFactory.UnregisterFilter(LogFilterName);
end.
