Class: Familia::FamiliaLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/familia/logging.rb

Overview

Custom Logger subclass with TRACE level support.

FamiliaLogger extends Ruby's standard Logger with a TRACE level for extremely detailed debugging output. The TRACE level is numerically equal to DEBUG (0) but distinguishes itself via a thread-local marker that the LogFormatter uses to output 'T' instead of 'D'.

Examples:

Basic usage

logger = Familia::FamiliaLogger.new($stderr)
logger.level = Familia::FamiliaLogger::TRACE
logger.trace "Detailed trace message"
# => T, 10-05 20:43:09.843 pid:123 [456/789]: Detailed trace message

With progname

logger.trace("MyApp") { "Trace with progname" }

See Also:

Constant Summary collapse

TRACE =

TRACE severity level (numerically equal to DEBUG=0).

Uses the same numeric level as DEBUG but signals via thread-local marker to output 'T' prefix instead of 'D'. This approach works around Logger's limitation with negative severity values.

Standard Logger levels: DEBUG=0, INFO=1, WARN=2, ERROR=3, FATAL=4, UNKNOWN=5

0

Instance Method Summary collapse

Instance Method Details

#trace(progname = nil) { ... } ⇒ true

Note:

Sets Fiber[:familia_trace_mode] during execution to signal LogFormatter to output 'T' instead of 'D'

Log a TRACE level message.

This method behaves like the standard Logger methods (debug, info, etc.) but outputs with a 'T' severity letter when used with LogFormatter.

Examples:

Simple message

logger.trace("Entering complex calculation")

With block for lazy evaluation

logger.trace { "Expensive: #{expensive_debug_info}" }

With progname

logger.trace("MyApp") { "Application trace" }

Parameters:

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

    Program name to include in log output

Yields:

  • Block that returns the message to log (lazy evaluation)

Returns:

  • (true)

    Always returns true



60
61
62
63
64
65
66
67
68
69
# File 'lib/familia/logging.rb', line 60

def trace(progname = nil, &)
  # Store marker in thread-local to signal this is TRACE not DEBUG
  # Track whether we set the flag to avoid clearing it in nested calls
  was_already_tracing = Fiber[:familia_trace_mode]
  Fiber[:familia_trace_mode] = true
  add(TRACE, nil, progname, &)
ensure
  # Only clear the flag if we set it (not already tracing)
  Fiber[:familia_trace_mode] = false unless was_already_tracing
end