Class: Gaskit::Configuration
- Inherits:
-
Object
- Object
- Gaskit::Configuration
- Defined in:
- lib/gaskit/configuration.rb
Overview
Gaskit::Configuration holds global configuration for the Gaskit gem.
It allows customization of logging behavior, including:
-
Log level (‘log_level`)
-
Custom logger (‘logger`)
-
Disabling logging entirely (‘disable_logging`)
-
Structured or custom log formatting (‘log_formatter`)
-
Debug mode (‘debug`)
Instance Attribute Summary collapse
-
#context_provider ⇒ Object
@return A callable to apply a global context used for all log entries.
-
#debug ⇒ Boolean
Whether debug mode is enabled.
-
#disable_logging ⇒ Boolean
Whether to completely suppress log output.
-
#logger ⇒ Logger
readonly
The logger instance used internally by Gaskit.
Instance Method Summary collapse
-
#contracts ⇒ Gaskit::ContractRegistry
Returns the ContractRegistry instance.
-
#hooks ⇒ Gaskit::HookRegistry
Returns the HookRegistry instance.
-
#initialize ⇒ Configuration
constructor
Initializes the configuration with default settings.
-
#log_formatter=(formatter) ⇒ Object
Sets a custom log formatter.
-
#log_level=(level) ⇒ Object
Sets the logging level.
-
#setup_logger(custom_logger = nil, level: :debug, formatter: nil) ⇒ Object
Sets the logger, formatter, and level in one go.
Constructor Details
#initialize ⇒ Configuration
Initializes the configuration with default settings.
The configuration includes:
-
Default environment set to ‘“development”`
-
Debug mode disabled
-
Logging to stdout
-
Default log level set to ::Logger::DEBUG
-
An empty base context hash
-
A new ‘ContractRegistry` instance for contract management
59 60 61 62 63 64 65 66 67 |
# File 'lib/gaskit/configuration.rb', line 59 def initialize @debug = false @disable_logging = false @context_provider = -> { {} } @contract_registry = ContractRegistry.new @hook_registry = HookRegistry.new setup_logger end |
Instance Attribute Details
#context_provider ⇒ Object
@return A callable to apply a global context used for all log entries.
48 49 50 |
# File 'lib/gaskit/configuration.rb', line 48 def context_provider @context_provider end |
#debug ⇒ Boolean
Returns Whether debug mode is enabled.
39 40 41 |
# File 'lib/gaskit/configuration.rb', line 39 def debug @debug end |
#disable_logging ⇒ Boolean
Returns Whether to completely suppress log output.
42 43 44 |
# File 'lib/gaskit/configuration.rb', line 42 def disable_logging @disable_logging end |
#logger ⇒ Logger (readonly)
Returns The logger instance used internally by Gaskit.
45 46 47 |
# File 'lib/gaskit/configuration.rb', line 45 def logger @logger end |
Instance Method Details
#contracts ⇒ Gaskit::ContractRegistry
Returns the ContractRegistry instance.
114 115 116 |
# File 'lib/gaskit/configuration.rb', line 114 def contracts @contract_registry end |
#hooks ⇒ Gaskit::HookRegistry
Returns the HookRegistry instance.
121 122 123 |
# File 'lib/gaskit/configuration.rb', line 121 def hooks @hook_registry end |
#log_formatter=(formatter) ⇒ Object
Sets a custom log formatter.
95 96 97 98 99 |
# File 'lib/gaskit/configuration.rb', line 95 def log_formatter=(formatter) raise ArgumentError, "Formatter must be callable" unless formatter.respond_to?(:call) @logger.formatter = formatter end |
#log_level=(level) ⇒ Object
Sets the logging level.
86 87 88 89 |
# File 'lib/gaskit/configuration.rb', line 86 def log_level=(level) level = ::Logger.const_get(level.upcase) if level.is_a?(Symbol) @logger.level = level end |
#setup_logger(custom_logger = nil, level: :debug, formatter: nil) ⇒ Object
Sets the logger, formatter, and level in one go.
74 75 76 77 78 79 80 |
# File 'lib/gaskit/configuration.rb', line 74 def setup_logger(custom_logger = nil, level: :debug, formatter: nil) @logger = custom_logger || ::Logger.new($stdout) effective_formatter = formatter || @logger&.formatter || Gaskit::Logger.formatter(:pretty) self.log_formatter = effective_formatter if effective_formatter.respond_to?(:call) self.log_level = level end |