TLoggingEventUnit.pas 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 TLoggingEvent class.
  15. @version 0.5
  16. @author <a href="mailto:tcmiller@users.sourceforge.net">Trevor Miller</a>
  17. ----------------------------------------------------------------------------}
  18. unit TLoggingEventUnit;
  19. {$ifdef fpc}
  20. {$mode objfpc}
  21. {$h+}
  22. {$endif}
  23. interface
  24. uses
  25. SysUtils,
  26. TLevelUnit;
  27. type
  28. {*----------------------------------------------------------------------------
  29. The internal representation of logging events. When an affirmative decision
  30. is made to log then a LoggingEvent instance is created. This instance is
  31. passed around to the different log4delphi components.
  32. ----------------------------------------------------------------------------}
  33. TLoggingEvent = class (TObject)
  34. private
  35. FLevel : TLevel;
  36. FMsg : String;
  37. FStartTime : TDateTime;
  38. FException : Exception;
  39. FLoggerName : String;
  40. public
  41. constructor Create(ALevel : TLevel; const AMsg : String;
  42. const ALoggerName : String); Overload;
  43. constructor Create(ALevel : TLevel;
  44. const AMsg : String; const ALoggerName : String;
  45. const AEx : Exception); Overload;
  46. destructor Destroy; Override;
  47. function GetLevel() : TLevel;
  48. function GetMessage() : String;
  49. function GetStartTime() : TDateTime;
  50. function GetException() : Exception;
  51. function GetLogger() : String;
  52. end;
  53. implementation
  54. {*----------------------------------------------------------------------------
  55. Instantiate a LoggingEvent from the supplied parameters.
  56. @param ALevel The level of this event
  57. @param AMsg The logging message
  58. ----------------------------------------------------------------------------}
  59. constructor TLoggingEvent.Create(ALevel : TLevel; const AMsg : String;
  60. const ALoggerName : String);
  61. begin
  62. inherited Create;
  63. Self.Create(ALevel, AMsg, ALoggerName, Nil);
  64. end;
  65. {*----------------------------------------------------------------------------
  66. Instantiate a LoggingEvent from the supplied parameters.
  67. @param ALevel The level of this event
  68. @param AMsg The logging message
  69. @param AEx The exception to use
  70. ----------------------------------------------------------------------------}
  71. constructor TLoggingEvent.Create(ALevel : TLevel; const AMsg : String;
  72. const ALoggerName : String; const AEx : Exception);
  73. begin
  74. inherited Create;
  75. Self.FLevel := ALevel;
  76. Self.FMsg := AMsg;
  77. Self.FException := AEx;
  78. Self.FStartTime := Now;
  79. Self.FLoggerName := ALoggerName;
  80. end;
  81. {*----------------------------------------------------------------------------
  82. Free this instance.
  83. ----------------------------------------------------------------------------}
  84. destructor TLoggingEvent.Destroy;
  85. begin
  86. inherited Destroy;
  87. end;
  88. {*----------------------------------------------------------------------------
  89. Return the level of this event.
  90. @return The level
  91. ----------------------------------------------------------------------------}
  92. function TLoggingEvent.GetLevel() : TLevel;
  93. begin
  94. Result := Self.FLevel;
  95. end;
  96. {*----------------------------------------------------------------------------
  97. Return the message for this logging event.
  98. @return The message
  99. ----------------------------------------------------------------------------}
  100. function TLoggingEvent.GetMessage() : String;
  101. begin
  102. Result := Self.FMsg;
  103. end;
  104. {*----------------------------------------------------------------------------
  105. Returns the time when the event was created.
  106. @return The creation time
  107. ----------------------------------------------------------------------------}
  108. function TLoggingEvent.GetStartTime() : TDateTime;
  109. begin
  110. Result := Self.FStartTime;
  111. end;
  112. {*----------------------------------------------------------------------------
  113. Returns the exception associated with this event.
  114. @return The associated exception
  115. ----------------------------------------------------------------------------}
  116. function TLoggingEvent.GetException() : Exception;
  117. begin
  118. Result := Self.FException;
  119. end;
  120. {*----------------------------------------------------------------------------
  121. Returns the name of the logger that created this event.
  122. @return The logger's name
  123. ----------------------------------------------------------------------------}
  124. function TLoggingEvent.GetLogger() : String;
  125. begin
  126. Result := Self.FLoggerName;
  127. end;
  128. end.