Class: AIHype::Logger
- Inherits:
-
Object
- Object
- AIHype::Logger
- Defined in:
- lib/aihype/logger.rb
Constant Summary collapse
- MAX_LOG_SIZE =
10MB
10 * 1024 * 1024
- MAX_LOG_FILES =
5
Instance Method Summary collapse
-
#initialize(log_file_path: 'memory/aihype.log', verbose: false) ⇒ Logger
constructor
A new instance of Logger.
- #log_ai_failure(prompt, error) ⇒ Object
- #log_approval(prompt) ⇒ Object
- #log_child_output(output) ⇒ Object
- #log_denial(prompt, rule_content) ⇒ Object
- #log_startup(rules_count, config_path) ⇒ Object
- #log_user_input(input) ⇒ Object
Constructor Details
#initialize(log_file_path: 'memory/aihype.log', verbose: false) ⇒ Logger
Returns a new instance of Logger.
11 12 13 14 15 |
# File 'lib/aihype/logger.rb', line 11 def initialize(log_file_path: 'memory/aihype.log', verbose: false) @log_file_path = log_file_path @verbose = verbose ensure_log_directory end |
Instance Method Details
#log_ai_failure(prompt, error) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/aihype/logger.rb', line 37 def log_ai_failure(prompt, error) = "WARNING: AI unavailable (#{error}), approving all prompts" = { prompt_id: prompt.id, error: error } entry = LogEntry.new(level: :warning, event_type: :ai_failure, message: , metadata: ) write(entry) end |
#log_approval(prompt) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/aihype/logger.rb', line 23 def log_approval(prompt) = "APPROVED: #{prompt.raw_text}" = { prompt_id: prompt.id, decision: prompt.decision } entry = LogEntry.new(level: :info, event_type: :prompt_detected, message: , metadata: ) write(entry) if @verbose end |
#log_child_output(output) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/aihype/logger.rb', line 51 def log_child_output(output) return unless @verbose # Log raw child output for debugging bidirectional I/O entry = LogEntry.new(level: :debug, event_type: :child_output, message: "Child output: #{output.inspect}") write(entry) end |
#log_denial(prompt, rule_content) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/aihype/logger.rb', line 30 def log_denial(prompt, rule_content) = "DENIED: #{prompt.raw_text} (matched rule: #{rule_content})" = { prompt_id: prompt.id, rule: rule_content } entry = LogEntry.new(level: :warning, event_type: :rule_matched, message: , metadata: ) write(entry) end |
#log_startup(rules_count, config_path) ⇒ Object
17 18 19 20 21 |
# File 'lib/aihype/logger.rb', line 17 def log_startup(rules_count, config_path) = "Loaded #{rules_count} blacklist rules from #{config_path}" entry = LogEntry.new(level: :info, event_type: :memory_loaded, message: ) write(entry) end |
#log_user_input(input) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/aihype/logger.rb', line 44 def log_user_input(input) return unless @verbose # Log raw user input for debugging bidirectional I/O entry = LogEntry.new(level: :debug, event_type: :user_input, message: "User input: #{input.inspect}") write(entry) end |