Class: Aidp::Logger
- Inherits:
-
Object
- Object
- Aidp::Logger
- 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
-
#json_format ⇒ Object
readonly
Returns the value of attribute json_format.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
-
#close ⇒ Object
Close all loggers.
-
#debug(component, message, **metadata) ⇒ Object
Log debug level message.
-
#error(component, message, **metadata) ⇒ Object
Log error level message.
-
#info(component, message, **metadata) ⇒ Object
Log info level message.
-
#initialize(project_dir = Dir.pwd, config = {}) ⇒ Logger
constructor
A new instance of Logger.
-
#log(level, component, message, **metadata) ⇒ Object
Log at specified level.
-
#warn(component, message, **metadata) ⇒ Object
Log warn level message.
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_format ⇒ Object (readonly)
Returns the value of attribute json_format.
55 56 57 |
# File 'lib/aidp/logger.rb', line 55 def json_format @json_format end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
55 56 57 |
# File 'lib/aidp/logger.rb', line 55 def level @level end |
Instance Method Details
#close ⇒ Object
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, , **) log(:debug, component, , **) end |
#error(component, message, **metadata) ⇒ Object
Log error level message
76 77 78 |
# File 'lib/aidp/logger.rb', line 76 def error(component, , **) log(:error, component, , **) end |
#info(component, message, **metadata) ⇒ Object
Log info level message
71 72 73 |
# File 'lib/aidp/logger.rb', line 71 def info(component, , **) log(:info, component, , **) 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, , **) return unless should_log?(level) # Redact sensitive data = redact() = redact_hash() write_entry(level, component, , ) end |
#warn(component, message, **metadata) ⇒ Object
Log warn level message
81 82 83 |
# File 'lib/aidp/logger.rb', line 81 def warn(component, , **) log(:warn, component, , **) end |