Class: Aidp::AutoUpdate::UpdateLogger

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from SafeDirectory

#safe_mkdir_p

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_fileObject (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

Parameters:



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

Parameters:

  • reason (String)

    Failure reason

  • checkpoint_id (String, nil) (defaults to: nil)

    Associated checkpoint ID



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

Parameters:

  • failure_count (Integer)

    Number of consecutive failures



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

Parameters:

  • checkpoint (Checkpoint)

    Checkpoint that was restored



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

Parameters:

  • from_version (String)

    Version updated from

  • to_version (String)

    Version updated to



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

Parameters:

  • checkpoint (Checkpoint)

    Checkpoint created for update

  • target_version (String) (defaults to: nil)

    Version updating to



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

Parameters:

  • limit (Integer) (defaults to: 10)

    Maximum number of entries to return

Returns:

  • (Array<Hash>)

    Recent 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.message)
  []
end