Class: FeatureEnvy::Inspect::LoggerAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/feature_envy/inspect.rb

Overview

An adapter class enabling the user of loggers for output.

output must respond to ‘#puts`, which precludes loggers. This adapter can be used to make loggers usable as outputs by logging at the desired level.

Examples:

# Given a logger, it can be used as inspection output by setting:
FeatureEnvy::Inspect.output = FeatureEnvy::Inspect::LoggerAdapter.new logger

Changing the log level

FeatureEnvy::Inspect.output =
  FeatureEnvy::Inspect::LoggerAdapter.new logger,
                                          level: Logger::INFO

Instance Method Summary collapse

Constructor Details

#initialize(logger, level: Logger::DEBUG) ⇒ LoggerAdapter

Initializes a new adapter for the specified logger.

Parameters:

  • logger (Logger)

    logger to use for output

  • level (Logger::DEBUG | Logger::INFO | Logger::WARN | Logger::ERROR | Logger::FATAL | Logger::UNKNOWN) (defaults to: Logger::DEBUG)

    level at which inspection results should be logged.



212
213
214
215
# File 'lib/feature_envy/inspect.rb', line 212

def initialize logger, level: Logger::DEBUG
  @logger = logger
  @level  = level
end

Instance Method Details

#puts(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



218
219
220
221
# File 'lib/feature_envy/inspect.rb', line 218

def puts string
  @logger.add @level, string
  nil
end