IdServerInterceptLogFile.pas 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 7/23/04 6:53:28 PM RLebeau
  18. TFileStream access right tweak for Init()
  19. Rev 1.4 07/07/2004 17:41:38 ANeillans
  20. Added IdGlobal to uses, was not compiling cleanly due to missing function
  21. WriteStringToStream.
  22. Rev 1.3 6/29/04 1:20:14 PM RLebeau
  23. Updated DoLogWriteString() to call WriteStringToStream() instead
  24. Rev 1.2 10/19/2003 5:57:22 PM DSiders
  25. Added localization comments.
  26. Rev 1.1 2003.10.17 8:20:42 PM czhower
  27. Removed const
  28. Rev 1.0 3/22/2003 10:59:22 PM BGooijen
  29. Initial check in.
  30. ServerIntercept to ease debugging, data/status are logged to a file
  31. }
  32. unit IdServerInterceptLogFile;
  33. interface
  34. {$i IdCompilerDefines.inc}
  35. uses
  36. IdServerInterceptLogBase,
  37. IdGlobal,
  38. Classes;
  39. type
  40. TIdServerInterceptLogFile = class(TIdServerInterceptLogBase)
  41. protected
  42. FFileStream: TFileStream;
  43. FFilename:string;
  44. public
  45. procedure Init; override;
  46. destructor Destroy; override;
  47. procedure DoLogWriteString(const AText: string); override;
  48. published
  49. property Filename: string read FFilename write FFilename;
  50. end;
  51. implementation
  52. uses
  53. IdBaseComponent, SysUtils;
  54. { TIdServerInterceptLogFile }
  55. destructor TIdServerInterceptLogFile.Destroy;
  56. begin
  57. FFileStream.Free;
  58. inherited Destroy;
  59. end;
  60. procedure TIdServerInterceptLogFile.Init;
  61. begin
  62. inherited Init;
  63. if not IsDesignTime then begin
  64. if FFilename = '' then begin
  65. FFilename := ChangeFileExt(ParamStr(0), '.log'); {do not localize} //BGO: TODO: Do we keep this, or maybe raise an exception?
  66. end;
  67. FFileStream := TIdAppendFileStream.Create(Filename);
  68. end;
  69. end;
  70. procedure TIdServerInterceptLogFile.DoLogWriteString(const AText: string);
  71. begin
  72. WriteStringToStream(FFileStream, AText, IndyTextEncoding_8Bit);
  73. end;
  74. end.