Module: Familia::Logging
- Included in:
- Familia
- Defined in:
- lib/familia/logging.rb
Overview
The Logging module provides logging capabilities for Familia.
Familia uses a custom FamiliaLogger that extends the standard Ruby Logger with a TRACE level for detailed debugging output.
== Log Levels (from most to least verbose):
- TRACE: Extremely detailed debugging (controlled by FAMILIA_TRACE env var)
- DEBUG: Detailed debugging information
- INFO: General informational messages
- WARN: Warning messages
- ERROR: Error messages
- FATAL: Fatal errors that cause termination
== Usage: # Use default logger Familia.info "Connection established" Familia.warn "Cache miss"
# Set custom logger Familia.logger = Logger.new('familia.log')
# Trace-level debugging (requires FAMILIA_TRACE=true) Familia.trace :LOAD, redis_client, "user:123", "from cache"
Instance Method Summary collapse
-
#info(msg) ⇒ true
Log an informational message.
-
#ld(msg) ⇒ true?
Log a debug message (only when Familia.debug? is true).
-
#le(msg) ⇒ true
Log an error message.
-
#logger ⇒ FamiliaLogger
Get the logger instance, initializing with defaults if not yet set.
-
#logger=(new_logger) ⇒ Logger
Set a custom logger instance.
-
#trace(label, instance_id = nil, ident = nil, extra_context = nil) ⇒ nil
Logs a structured trace message for debugging Familia operations.
-
#warn(msg) ⇒ true
Log a warning message.
Instance Method Details
#info(msg) ⇒ true
Log an informational message.
224 225 226 |
# File 'lib/familia/logging.rb', line 224 def info(msg) logger.info(msg) end |
#ld(msg) ⇒ true?
Log a debug message (only when Familia.debug? is true).
Short for "log debug". Only outputs when FAMILIA_DEBUG environment variable is set to '1' or 'true'.
252 253 254 |
# File 'lib/familia/logging.rb', line 252 def ld(msg) logger.debug(msg) if Familia.debug? end |
#le(msg) ⇒ true
Log an error message.
Short for "log error".
266 267 268 |
# File 'lib/familia/logging.rb', line 266 def le(msg) logger.error(msg) end |
#logger ⇒ FamiliaLogger
Get the logger instance, initializing with defaults if not yet set
189 190 191 192 193 194 |
# File 'lib/familia/logging.rb', line 189 def logger @logger ||= FamiliaLogger.new($stderr).tap do |log| log.progname = name log.formatter = LogFormatter.new end end |
#logger=(new_logger) ⇒ Logger
Set a custom logger instance.
Allows replacing the default FamiliaLogger with any Logger-compatible object. Useful for integrating with application logging frameworks.
212 213 214 |
# File 'lib/familia/logging.rb', line 212 def logger=(new_logger) @logger = new_logger end |
#trace(label, instance_id = nil, ident = nil, extra_context = nil) ⇒ nil
Controlled by FAMILIA_TRACE environment variable (set to '1', 'true', or 'yes')
The instance_id can be a Redis client, Redis::Future, or nil
Logs a structured trace message for debugging Familia operations.
This method only executes when both FAMILIA_TRACE and FAMILIA_DEBUG environment variables are enabled.
290 291 292 293 294 295 |
# File 'lib/familia/logging.rb', line 290 def trace(label, instance_id = nil, ident = nil, extra_context = nil) return unless trace_enabled? && Familia.debug? ident_str = ident.nil? ? '<nil>' : ident.to_s logger.trace format('[%s] %s -> %s <-%s', label, instance_id, ident_str, extra_context) end |
#warn(msg) ⇒ true
Log a warning message.
236 237 238 |
# File 'lib/familia/logging.rb', line 236 def warn(msg) logger.warn(msg) end |