lib/dry/web/container.rb in dry-web-0.7.1 vs lib/dry/web/container.rb in dry-web-0.8.0
- old
+ new
@@ -2,44 +2,26 @@
require 'dry/monitor'
module Dry
module Web
class Container < Dry::System::Container
- setting :env, ENV.fetch('RACK_ENV', 'development').to_sym
- setting :log_dir, 'log'.freeze
- setting :log_levels, development: Logger::DEBUG, test: Logger::DEBUG
- setting :logger
+ use :env, inferrer: -> { ENV.fetch('RACK_ENV', 'development').to_sym }
+ use :logging
+ use :notifications
+
+ setting :logger_class, Monitor::Logger
setting :listeners, false
- class << self
- def configure(&block)
- super.
- configure_logger.
- configure_notifications.
- configure_rack_monitor.
- attach_listeners
+ def self.inherited(klass)
+ klass.after(:configure) do
+ register_rack_monitor
+ attach_listeners
end
+ super
+ end
- def configure_logger
- if key?(:logger)
- self
- elsif config.logger
- register(:logger, config.logger)
- else
- config.logger = Monitor::Logger.new(config.root.join(config.log_dir).realpath.join("#{config.env}.log"))
- config.logger.level = config.log_levels.fetch(config.env, Logger::ERROR)
- register(:logger, config.logger)
- self
- end
- end
-
- def configure_notifications
- return self if key?(:notifications)
- register(:notifications, Monitor::Notifications.new(config.name))
- self
- end
-
- def configure_rack_monitor
+ class << self
+ def register_rack_monitor
return self if key?(:rack_monitor)
register(:rack_monitor, Monitor::Rack::Middleware.new(self[:notifications]))
self
end