| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- { $HDR$}
- {**********************************************************************}
- { Unit archived using Team Coherence }
- { Team Coherence is Copyright 2002 by Quality Software Components }
- { }
- { For further information / comments, visit our WEB site at }
- { http://www.TeamCoherence.com }
- {**********************************************************************}
- {}
- { $Log: 10357: IdSysLog.pas
- {
- { Rev 1.2 15.9.2003 12:34:08 TPrami
- { - if not AUsePID now Process information will be written also
- }
- {
- { Rev 1.0 2002.11.12 10:54:32 PM czhower
- }
- unit IdSysLog;
- // Copyright the Indy pit crew
- // Original Author: Stephane Grobety ([email protected])
- // Release history:
- //
- // 09/19/01; J. Peter Mugaas
- // devided SysLogMessage into this unit
- // 08/09/01: Dev started
- {ToDo: Somehow figure out how to make a bound port and bound IP property
- in UDP Client. This will probably require some changes to the Indy core units
- though.
- }
- interface
- uses
- Classes, IdAssignedNumbers, IdSocketHandle, IdSysLogMessage, IdUDPBase, IdUDPClient;
- type
- TIdSysLog = class(TIdUDPClient)
- protected
- function GetBinding: TIdSocketHandle; override;
- public
- constructor Create(AOwner: TComponent); override;
- procedure SendMsg(const AMsg: TIdSysLogMessage; const AAutoTimeStamp: Boolean = True); overload;
- procedure SendMsg(const AMsg: String; const AFacility : TidSyslogFacility; const ASeverity: TIdSyslogSeverity); overload;
- procedure SendMsg(const AProcess: String; const AText : String; const AFacility : TidSyslogFacility;
- const ASeverity: TIdSyslogSeverity; const AUsePID : Boolean = False; const APID : Integer = -1); overload;
- published
- property Port default IdPORT_syslog;
- end;
-
- implementation
- uses
- IdGlobal, SysUtils, IdStackConsts;
- { TIdSysLog }
- constructor TIdSysLog.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Port := IdPORT_syslog;
- end;
- procedure TIdSysLog.SendMsg(const AMsg: TIdSyslogMessage; const AAutoTimeStamp: Boolean = True);
- begin
- if AAutoTimeStamp then begin
- AMsg.TimeStamp := Now;
- end;
- Send(AMsg.EncodeMessage);
- end;
- function TIdSysLog.GetBinding: TIdSocketHandle;
- const
- FromPort = 514;
- begin
- Result := inherited GetBinding;
- // if Result.Port <> FromPort then
- // begin
- // {Recommened by RFC 3164 - Use 514 as to connect to the SysLog server}
- // Result.Port := FromPort;
- // Result.SetSockOpt(Id_SOL_SOCKET, Id_SO_REUSEADDR, PChar(@Id_SO_True), SizeOf(Id_SO_True));
- // Result.Bind;
- // end;
- end;
- procedure TIdSysLog.SendMsg(const AMsg: String; const AFacility: TidSyslogFacility;
- const ASeverity: TIdSyslogSeverity);
- var
- LMsg : TIdSyslogMessage;
- begin
- LMsg := TIdSyslogMessage.Create(nil);
- try
- LMsg.Msg.Text := AMsg;
- LMsg.Facility := AFacility;
- LMsg.Severity := ASeverity;
- SendMsg(LMsg);
- finally
- FreeAndNil(LMsg);
- end;
- end;
- procedure TIdSysLog.SendMsg(const AProcess, AText: String;
- const AFacility: TidSyslogFacility; const ASeverity: TIdSyslogSeverity;
- const AUsePID: Boolean; const APID: Integer);
- var
- LMsg : TIdSyslogMessage;
- begin
- LMsg := TIdSyslogMessage.Create(nil);
- try
- LMsg.Msg.PIDAvailable := AUsePID;
- LMsg.Msg.Process := AProcess;
- // <TP>
- // AUsePID was not honored
- LMsg.Msg.PIDAvailable := AUsePID;
- if AUsePID then begin
- LMsg.Msg.PID := APID;
- LMsg.Msg.Content := AText;
- end else begin
- LMsg.Msg.Content := AText;
- end;
- // </TP>
- LMsg.Facility := AFacility;
- LMsg.Severity := ASeverity;
- SendMsg(LMsg);
- finally
- FreeAndNil(LMsg);
- end;
- end;
- end.
|