lib/dry/monitor/rack/logger.rb in dry-monitor-0.3.2 vs lib/dry/monitor/rack/logger.rb in dry-monitor-0.4.0

- old
+ new

@@ -19,31 +19,21 @@ START_MSG = %(Started %s "%s" for %s at %s) STOP_MSG = %(Finished %s "%s" for %s in %sms [Status: %s]\n) QUERY_MSG = %( Query parameters ) FILTERED = "[FILTERED]" - attr_reader :logger + attr_reader :logger, :config - attr_reader :config - def initialize(logger, config = self.class.config) @logger = logger @config = config end def attach(rack_monitor) - rack_monitor.on(:start) do |env:| - log_start_request(env) - end - - rack_monitor.on(:stop) do |env:, status:, time:| - log_stop_request(env, status, time) - end - - rack_monitor.on(:error) do |event| - log_exception(event[:exception]) - end + rack_monitor.on(:start) { |params| log_start_request(params[:env]) } + rack_monitor.on(:stop) { |params| log_stop_request(**params) } + rack_monitor.on(:error) { |event| log_exception(event[:exception]) } end def log_exception(err) logger.error err.message logger.error filter_backtrace(err.backtrace).join("\n") @@ -57,14 +47,14 @@ Time.now ] log_request_params(request) end - def log_stop_request(request, status, time) + def log_stop_request(env:, status:, time:) logger.info STOP_MSG % [ - request[REQUEST_METHOD], - request[PATH_INFO], - request[REMOTE_ADDR], + env[REQUEST_METHOD], + env[PATH_INFO], + env[REMOTE_ADDR], time, status ] end