IdLogStream.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.5 2004.05.20 12:34:32 PM czhower
  18. Removed more non .NET compatible stream read and writes
  19. Rev 1.4 2004.01.20 10:03:30 PM czhower
  20. InitComponent
  21. Rev 1.3 2003.10.17 6:15:56 PM czhower
  22. Upgrades
  23. Rev 1.2 2003.10.17 4:28:54 PM czhower
  24. Changed stream names to be consistent with IOHandlerStream
  25. Rev 1.1 2003.10.14 1:27:12 PM czhower
  26. Uupdates + Intercept support
  27. Rev 1.0 11/13/2002 07:56:18 AM JPMugaas
  28. }
  29. unit IdLogStream;
  30. interface
  31. {$I IdCompilerDefines.inc}
  32. //Put FPC into Delphi mode
  33. uses
  34. Classes,
  35. IdLogBase, IdGlobal;
  36. type
  37. TIdLogStream = class(TIdLogBase)
  38. protected
  39. FFreeStreams: Boolean;
  40. FReceiveStream: TStream;
  41. FSendStream: TStream;
  42. //
  43. procedure LogStatus(const AText: string); override;
  44. procedure LogReceivedData(const AText, AData: string); override;
  45. procedure LogSentData(const AText, AData: string); override;
  46. public
  47. constructor Create(AOwner: TComponent); override;
  48. procedure Disconnect; override;
  49. //
  50. property FreeStreams: Boolean read FFreeStreams write FFreeStreams;
  51. property ReceiveStream: TStream read FReceiveStream write FReceiveStream;
  52. property SendStream: TStream read FSendStream write FSendStream;
  53. end;
  54. implementation
  55. uses
  56. SysUtils;
  57. // TODO: This was orginally for VCL. For .Net what do we do? Convert back to
  58. // 7 bit? Log all? Logging all seems to be a disaster.
  59. // Text seems to be best, users are expecting text in this class. But
  60. // this write stream will dump unicode out in .net.....
  61. // So just convert it again back to 7 bit? How is proper to write
  62. // 7 bit to file? Use AnsiString?
  63. { TIdLogStream }
  64. constructor TIdLogStream.Create(AOwner: TComponent);
  65. begin
  66. inherited Create(AOwner);
  67. FFreeStreams := True;
  68. end;
  69. procedure TIdLogStream.Disconnect;
  70. begin
  71. inherited Disconnect;
  72. if FreeStreams then begin
  73. IdDisposeAndNil(FReceiveStream);
  74. IdDisposeAndNil(FSendStream);
  75. end;
  76. end;
  77. procedure TIdLogStream.LogReceivedData(const AText, AData: string);
  78. begin
  79. if FReceiveStream <> nil then begin
  80. WriteStringToStream(FReceiveStream, AData, IndyTextEncoding_8Bit);
  81. end;
  82. end;
  83. procedure TIdLogStream.LogSentData(const AText, AData: string);
  84. begin
  85. if FSendStream <> nil then begin
  86. WriteStringToStream(FSendStream, AData, IndyTextEncoding_8Bit);
  87. end;
  88. end;
  89. procedure TIdLogStream.LogStatus(const AText: string);
  90. begin
  91. // We just leave this empty because the AText is not part of the stream and we
  92. // do not want to raise an abstract method exception.
  93. end;
  94. end.