TLayoutUnit.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. Copyright 2005-2006 Log4Delphi Project
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. }
  13. {*----------------------------------------------------------------------------
  14. Contains the TLayout class.
  15. @version 0.5
  16. @author <a href="mailto:tcmiller@users.sourceforge.net">Trevor Miller</a>
  17. ----------------------------------------------------------------------------}
  18. unit TLayoutUnit;
  19. {$ifdef fpc}
  20. {$mode objfpc}
  21. {$h+}
  22. {$endif}
  23. interface
  24. uses
  25. TLoggingEventUnit;
  26. {*-------------------------------------------------------------------------
  27. A line separator consisting of ASCII characters 13 and 10.
  28. -------------------------------------------------------------------------}
  29. const
  30. LINE_SEP = #13#10;
  31. type
  32. {*----------------------------------------------------------------------------
  33. This abstract class should be extended to create specific log layout
  34. formats.
  35. ----------------------------------------------------------------------------}
  36. TLayout = class (TObject)
  37. private
  38. protected
  39. public
  40. function Format(AEvent : TLoggingEvent) : String; Virtual; Abstract;
  41. function GetContentType() : String; Virtual;
  42. function GetHeader() : String; Virtual;
  43. function GetFooter() : String; Virtual;
  44. function IgnoresException() : Boolean; Virtual;
  45. end;
  46. implementation
  47. {*----------------------------------------------------------------------------
  48. Returns the content type output by this layout. The default implementation
  49. returns "text/plain".
  50. @return Content type
  51. ----------------------------------------------------------------------------}
  52. function TLayout.GetContentType() : String;
  53. begin
  54. Result := 'text/plain';
  55. end;
  56. {*----------------------------------------------------------------------------
  57. Returns the header for the layout format. The default implementation
  58. returns the empty string ''.
  59. @return Header
  60. ----------------------------------------------------------------------------}
  61. function TLayout.GetHeader() : String;
  62. begin
  63. Result := '';
  64. end;
  65. {*----------------------------------------------------------------------------
  66. Returns the footer for the layout format. The default implementation
  67. returns the empty string ''.
  68. @return Footer
  69. ----------------------------------------------------------------------------}
  70. function TLayout.GetFooter() : String;
  71. begin
  72. Result := '';
  73. end;
  74. {*----------------------------------------------------------------------------
  75. If the layout handles the Exception object contained within LoggingEvent,
  76. then the layout should return false. Otherwise, if the layout ignores
  77. Exception object, then the layout should return true.
  78. @return Whether the exception is handled or not
  79. ----------------------------------------------------------------------------}
  80. function TLayout.ignoresException() : Boolean;
  81. begin
  82. IgnoresException := true;
  83. end;
  84. end.