Class: KairosMcp::Logger
- Inherits:
-
Object
- Object
- KairosMcp::Logger
- Defined in:
- lib/kairos_mcp/logger.rb
Overview
Structured JSON lines logger for KairosChain. Writes to .kairos/logs/kairos.log with daily rotation (max 7 files). All entries pass through SecretRedactor before writing.
Log levels: DEBUG, INFO, WARN, ERROR Entry format: “ts”,“level”,“event”,“source”,“details”,…
Constant Summary collapse
- LEVELS =
{ debug: 0, info: 1, warn: 2, error: 3 }.freeze
- MAX_ROTATED_FILES =
7- DEFAULT_LOG_DIR =
'.kairos/logs'- DEFAULT_LOG_FILE =
'kairos.log'- SECRET_PATTERNS =
Patterns for secret redaction (applied to serialized JSON). Uses simple patterns compatible with Ruby 3.1+ (no variable-length lookbehind).
[ # Bare API key formats (provider-specific prefixes) /\b(sk-[a-zA-Z0-9]{20,})\b/, /\b(anthropic-[a-zA-Z0-9]{20,})\b/, /\b(ghp_[a-zA-Z0-9]{20,})\b/, /\b(xoxb-[a-zA-Z0-9\-]{20,})\b/, ].freeze
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#log_path ⇒ Object
readonly
Returns the value of attribute log_path.
Instance Method Summary collapse
-
#close ⇒ Object
Flush and close the log file.
- #debug(event, **fields) ⇒ Object
- #error(event, **fields) ⇒ Object
- #info(event, **fields) ⇒ Object
-
#initialize(log_dir: nil, level: :info) ⇒ Logger
constructor
A new instance of Logger.
- #warn(event, **fields) ⇒ Object
Constructor Details
#initialize(log_dir: nil, level: :info) ⇒ Logger
Returns a new instance of Logger.
34 35 36 37 38 39 40 41 |
# File 'lib/kairos_mcp/logger.rb', line 34 def initialize(log_dir: nil, level: :info) @log_dir = log_dir || File.join(Dir.pwd, DEFAULT_LOG_DIR) @level = LEVELS[level] || LEVELS[:info] @log_path = File.join(@log_dir, DEFAULT_LOG_FILE) @mutex = Mutex.new @current_date = nil @io = nil end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
30 31 32 |
# File 'lib/kairos_mcp/logger.rb', line 30 def level @level end |
#log_path ⇒ Object (readonly)
Returns the value of attribute log_path.
30 31 32 |
# File 'lib/kairos_mcp/logger.rb', line 30 def log_path @log_path end |
Instance Method Details
#close ⇒ Object
Flush and close the log file.
60 61 62 63 64 65 |
# File 'lib/kairos_mcp/logger.rb', line 60 def close @mutex.synchronize do @io&.close @io = nil end end |
#debug(event, **fields) ⇒ Object
43 44 45 |
# File 'lib/kairos_mcp/logger.rb', line 43 def debug(event, **fields) write_entry(:debug, event, fields) end |
#error(event, **fields) ⇒ Object
55 56 57 |
# File 'lib/kairos_mcp/logger.rb', line 55 def error(event, **fields) write_entry(:error, event, fields) end |
#info(event, **fields) ⇒ Object
47 48 49 |
# File 'lib/kairos_mcp/logger.rb', line 47 def info(event, **fields) write_entry(:info, event, fields) end |
#warn(event, **fields) ⇒ Object
51 52 53 |
# File 'lib/kairos_mcp/logger.rb', line 51 def warn(event, **fields) write_entry(:warn, event, fields) end |