Class: Makit::Logging::Sinks::Console

Inherits:
UnifiedFileSink show all
Defined in:
lib/makit/logging/sinks/console.rb

Overview

Console sink for clean, colored log output

This is a thin wrapper around UnifiedFileSink that provides a simple API for console output. It maintains backward compatibility while leveraging the unified logging architecture.

Examples:

Basic usage

console = Console.new
logger = Logger.new(sinks: [console])
logger.info("Processing started")
# Shows: → Processing started

With custom formatter options

console = Console.new(show_timestamp: true, show_level: true)

With custom formatter

console = Console.new(formatter: :text)

Instance Attribute Summary collapse

Attributes inherited from UnifiedFileSink

#configurations

Instance Method Summary collapse

Methods inherited from UnifiedFileSink

#call

Methods inherited from Base

#applicable?, #call, #name

Constructor Details

#initialize(formatter: :console, show_timestamp: false, show_level: false, **formatter_options) ⇒ Console

Initialize console sink



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/makit/logging/sinks/console.rb', line 35

def initialize(formatter: :console, show_timestamp: false, show_level: false, **formatter_options)
  @format = formatter.to_sym

  # Build configuration for UnifiedFileSink

  configuration = {
    file: $stdout,
    format: @format,
    formatter_options: {
      show_timestamp: show_timestamp,
      show_level: show_level,
    }.merge(formatter_options),
  }

  super(configurations: [configuration])
end

Instance Attribute Details

#formatSymbol (readonly)



27
28
29
# File 'lib/makit/logging/sinks/console.rb', line 27

def format
  @format
end

Instance Method Details

#configHash

Get sink configuration



54
55
56
57
58
59
60
61
# File 'lib/makit/logging/sinks/console.rb', line 54

def config
  {
    name: self.class.name.split("::").last,
    format: @format,
    colors_enabled: true,
    unified_sink: true,
  }
end

#console?Boolean

Check if this is a console sink (for compatibility)



66
67
68
# File 'lib/makit/logging/sinks/console.rb', line 66

def console?
  true
end