Method: Hanami::Config#logger_instance

Defined in:
lib/hanami/config.rb

#logger_instanceDry::Logger::Dispatcher

Returns the configured logger instance.

Unless you’ve replaced the logger with #logger=, this returns a ‘Dry::Logger::Dispatcher` configured with the options configured through #logger.

This configured logger is registered in all app and slice containers as ‘“logger”`. For typical usage, you should access the logger via this component, not directly from config.

Examples:

Accessing the logger component

Hanami.app["logger"] # => #<Dry::Logger::Dispatcher>

Injecting the logger as a dependency

module MyApp
  class MyClass
    include Deps["logger"]

    def my_method
      logger.info("hello")
    end
  end
end

Returns:

  • (Dry::Logger::Dispatcher)

See Also:

Since:

  • 2.0.0


464
465
466
# File 'lib/hanami/config.rb', line 464

def logger_instance
  @logger_instance || logger.instance
end