unit fwLogging;

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}

interface

uses SysUtils;

type
  //----------------------------------------------------------------------
  // fwLogger
  //
  // Implementierung einer einfache Protokollierung von Meldungen in eine
  // Datei. Dies is ein globales Objekt.
  //----------------------------------------------------------------------
  TfwLogger        = class(TObject)
  private
    fLog             : System.Text;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Write(const aMessage : String); overload;
    procedure Write(const aMessage : String; aParams : array of Const); overload;
  end;

procedure fwLOG(const aMessage : String);

implementation

constructor TfwLogger.Create;
begin
  inherited Create;

  AssignFile(fLog, 'output.log');
  Rewrite(fLog);
end;

destructor TfwLogger.Destroy;
begin
  CloseFile(fLog);
  
  inherited Destroy;
end;

procedure TfwLogger.Write(const aMessage : String);
begin
{$IFDEF FPC}
{$IFDEF LINUX}
  WriteLn(aMessage);
{$ENDIF}
{$ENDIF}
  WriteLn(fLog, aMessage);
end;

procedure TfwLogger.Write(const aMessage : String; aParams : array of Const);
begin
{$IFDEF FPC}
{$IFDEF LINUX}
  WriteLn(Format(aMessage, aParams));
{$ENDIF}
{$ENDIF}
  WriteLn(fLog, Format(aMessage, aParams));
end;

var
  Logger           : TfwLogger;

procedure fwLOG(const aMessage : String);
begin
  Logger.Write(aMessage)
end;

initialization

  Logger := TfwLogger.Create;

finalization

  FreeAndNil(Logger);

end.



