Class: Aidp::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/logger.rb

Overview

Unified structured logger for all AIDP operations Supports:

  • Multiple log levels (info, error, debug)

  • Text and JSONL formats

  • Automatic rotation

  • Redaction of secrets

  • Consistent file layout in .aidp/logs/

Usage:

Aidp.setup_logger(project_dir, config)
Aidp.logger.info("component", "message", key: "value")

Defined Under Namespace

Classes: SafeLogDevice

Constant Summary collapse

LEVELS =
{
  debug: ::Logger::DEBUG,
  info: ::Logger::INFO,
  warn: ::Logger::WARN,
  error: ::Logger::ERROR
}.freeze
LOG_DIR =
".aidp/logs"
INFO_LOG =
"#{LOG_DIR}/aidp.log"
DEFAULT_MAX_SIZE =

10MB

10 * 1024 * 1024
DEFAULT_MAX_FILES =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_dir = Dir.pwd, config = {}) ⇒ Logger

Returns a new instance of Logger.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/aidp/logger.rb', line 57

def initialize(project_dir = Dir.pwd, config = {})
  @project_dir = sanitize_project_dir(project_dir)
  @config = config
  @level = determine_log_level
  @json_format = config[:json] || false
  @max_size = config[:max_size_mb] ? config[:max_size_mb] * 1024 * 1024 : DEFAULT_MAX_SIZE
  @max_files = config[:max_backups] || DEFAULT_MAX_FILES
  @instrument_internal = config.key?(:instrument) ? config[:instrument] : (ENV["AIDP_LOG_INSTRUMENT"] == "1")

  ensure_log_directory
  setup_logger
end

Instance Attribute Details

#json_formatObject (readonly)

Returns the value of attribute json_format.



55
56
57
# File 'lib/aidp/logger.rb', line 55

def json_format
  @json_format
end

#levelObject (readonly)

Returns the value of attribute level.



55
56
57
# File 'lib/aidp/logger.rb', line 55

def level
  @level
end

Instance Method Details

#closeObject

Close all loggers



102
103
104
# File 'lib/aidp/logger.rb', line 102

def close
  @logger&.close
end

#debug(component, message, **metadata) ⇒ Object

Log debug level message



86
87
88
# File 'lib/aidp/logger.rb', line 86

def debug(component, message, **)
  log(:debug, component, message, **)
end

#error(component, message, **metadata) ⇒ Object

Log error level message



76
77
78
# File 'lib/aidp/logger.rb', line 76

def error(component, message, **)
  log(:error, component, message, **)
end

#info(component, message, **metadata) ⇒ Object

Log info level message



71
72
73
# File 'lib/aidp/logger.rb', line 71

def info(component, message, **)
  log(:info, component, message, **)
end

#log(level, component, message, **metadata) ⇒ Object

Log at specified level



91
92
93
94
95
96
97
98
99
# File 'lib/aidp/logger.rb', line 91

def log(level, component, message, **)
  return unless should_log?(level)

  # Redact sensitive data
  safe_message = redact(message)
   = redact_hash()

  write_entry(level, component, safe_message, )
end

#warn(component, message, **metadata) ⇒ Object

Log warn level message



81
82
83
# File 'lib/aidp/logger.rb', line 81

def warn(component, message, **)
  log(:warn, component, message, **)
end