Class: AIHype::LogEntry
- Inherits:
-
Object
- Object
- AIHype::LogEntry
- Defined in:
- lib/aihype/log_entry.rb
Constant Summary collapse
- VALID_LEVELS =
%i[info warning error].freeze
- VALID_EVENT_TYPES =
%i[prompt_detected rule_matched ai_failure memory_loaded].freeze
Instance Attribute Summary collapse
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#initialize(level:, event_type:, message:, metadata: {}) ⇒ LogEntry
constructor
A new instance of LogEntry.
- #to_json(*_args) ⇒ Object
- #to_stderr ⇒ Object
Constructor Details
#initialize(level:, event_type:, message:, metadata: {}) ⇒ LogEntry
Returns a new instance of LogEntry.
12 13 14 15 16 17 18 19 20 |
# File 'lib/aihype/log_entry.rb', line 12 def initialize(level:, event_type:, message:, metadata: {}) @timestamp = Time.now @level = level @event_type = event_type @message = @metadata = validate! end |
Instance Attribute Details
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
7 8 9 |
# File 'lib/aihype/log_entry.rb', line 7 def event_type @event_type end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
7 8 9 |
# File 'lib/aihype/log_entry.rb', line 7 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/aihype/log_entry.rb', line 7 def @message end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/aihype/log_entry.rb', line 7 def @metadata end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/aihype/log_entry.rb', line 7 def @timestamp end |
Instance Method Details
#to_json(*_args) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/aihype/log_entry.rb', line 22 def to_json(*_args) { timestamp: .iso8601, level: level.to_s.upcase, event_type: event_type.to_s, message: , metadata: }.to_json end |
#to_stderr ⇒ Object
32 33 34 |
# File 'lib/aihype/log_entry.rb', line 32 def to_stderr "[AIHype] #{level.to_s.upcase}: #{}" end |