Class: Aidp::AutoUpdate::UpdateLogger
- Inherits:
-
Object
- Object
- Aidp::AutoUpdate::UpdateLogger
- Includes:
- SafeDirectory
- Defined in:
- lib/aidp/auto_update/update_logger.rb
Overview
Service for logging update events in JSON Lines format
Instance Attribute Summary collapse
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
Instance Method Summary collapse
-
#initialize(project_dir: Dir.pwd) ⇒ UpdateLogger
constructor
A new instance of UpdateLogger.
-
#log_check(update_check) ⇒ Object
Log an update check.
-
#log_failure(reason, checkpoint_id: nil) ⇒ Object
Log update failure.
-
#log_restart_loop(failure_count) ⇒ Object
Log restart loop detection.
-
#log_restore(checkpoint) ⇒ Object
Log successful checkpoint restoration.
-
#log_success(from_version:, to_version:) ⇒ Object
Log successful update completion.
-
#log_update_initiated(checkpoint, target_version: nil) ⇒ Object
Log update initiation.
-
#recent_entries(limit: 10) ⇒ Array<Hash>
Read recent update log entries.
Methods included from SafeDirectory
Constructor Details
#initialize(project_dir: Dir.pwd) ⇒ UpdateLogger
Returns a new instance of UpdateLogger.
16 17 18 19 20 21 |
# File 'lib/aidp/auto_update/update_logger.rb', line 16 def initialize(project_dir: Dir.pwd) @project_dir = project_dir log_dir = File.join(project_dir, ".aidp", "logs") actual_dir = safe_mkdir_p(log_dir, component_name: "UpdateLogger") @log_file = File.join(actual_dir, "updates.log") end |
Instance Attribute Details
#log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
14 15 16 |
# File 'lib/aidp/auto_update/update_logger.rb', line 14 def log_file @log_file end |
Instance Method Details
#log_check(update_check) ⇒ Object
Log an update check
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/aidp/auto_update/update_logger.rb', line 25 def log_check(update_check) write_log_entry( event: "check", current_version: update_check.current_version, available_version: update_check.available_version, update_available: update_check.update_available, update_allowed: update_check.update_allowed, policy_reason: update_check.policy_reason, error: update_check.error ) end |
#log_failure(reason, checkpoint_id: nil) ⇒ Object
Log update failure
65 66 67 68 69 70 71 72 |
# File 'lib/aidp/auto_update/update_logger.rb', line 65 def log_failure(reason, checkpoint_id: nil) write_log_entry( event: "failure", reason: reason, checkpoint_id: checkpoint_id, version: Aidp::VERSION ) end |
#log_restart_loop(failure_count) ⇒ Object
Log restart loop detection
87 88 89 90 91 92 93 |
# File 'lib/aidp/auto_update/update_logger.rb', line 87 def log_restart_loop(failure_count) write_log_entry( event: "restart_loop_detected", failure_count: failure_count, version: Aidp::VERSION ) end |
#log_restore(checkpoint) ⇒ Object
Log successful checkpoint restoration
52 53 54 55 56 57 58 59 60 |
# File 'lib/aidp/auto_update/update_logger.rb', line 52 def log_restore(checkpoint) write_log_entry( event: "restore", checkpoint_id: checkpoint.checkpoint_id, from_version: checkpoint.aidp_version, restored_version: Aidp::VERSION, mode: checkpoint.mode ) end |
#log_success(from_version:, to_version:) ⇒ Object
Log successful update completion
77 78 79 80 81 82 83 |
# File 'lib/aidp/auto_update/update_logger.rb', line 77 def log_success(from_version:, to_version:) write_log_entry( event: "success", from_version: from_version, to_version: to_version ) end |
#log_update_initiated(checkpoint, target_version: nil) ⇒ Object
Log update initiation
40 41 42 43 44 45 46 47 48 |
# File 'lib/aidp/auto_update/update_logger.rb', line 40 def log_update_initiated(checkpoint, target_version: nil) write_log_entry( event: "update_initiated", checkpoint_id: checkpoint.checkpoint_id, from_version: checkpoint.aidp_version, to_version: target_version, mode: checkpoint.mode ) end |
#recent_entries(limit: 10) ⇒ Array<Hash>
Read recent update log entries
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/aidp/auto_update/update_logger.rb', line 98 def recent_entries(limit: 10) return [] unless File.exist?(@log_file) entries = [] File.readlines(@log_file).reverse_each do |line| break if entries.size >= limit begin entries << JSON.parse(line, symbolize_names: true) rescue JSON::ParserError # Skip malformed lines end end entries rescue => e Aidp.log_error("update_logger", "read_entries_failed", error: e.) [] end |