lib/dry/monitor/rack/logger.rb in dry-monitor-0.0.3 vs lib/dry/monitor/rack/logger.rb in dry-monitor-0.1.0
- old
+ new
@@ -9,16 +9,14 @@
setting :filtered_params, %w[_csrf password]
REQUEST_METHOD = 'REQUEST_METHOD'.freeze
PATH_INFO = 'PATH_INFO'.freeze
REMOTE_ADDR = 'REMOTE_ADDR'.freeze
- RACK_INPUT = 'rack.input'.freeze
- QUERY_PARAMS = 'QUERY_PARAMS'.freeze
+ QUERY_STRING = 'QUERY_STRING'.freeze
START_MSG = %(Started %s "%s" for %s at %s).freeze
STOP_MSG = %(Finished %s "%s" for %s in %sms [Status: %s]\n).freeze
- PARAMS_MSG = %( Parameters %s).freeze
QUERY_MSG = %( Query parameters %s).freeze
FILTERED = '[FILTERED]'.freeze
attr_reader :logger
@@ -28,26 +26,26 @@
@logger = logger
@config = config
end
def attach(rack_monitor)
- rack_monitor.on(:start) do |id, payload|
- log_start_request(payload[:env])
+ rack_monitor.on(:start) do |env:|
+ log_start_request(env)
end
- rack_monitor.on(:stop) do |id, payload|
- log_stop_request(payload[:env], payload[:status], payload[:time])
+ rack_monitor.on(:stop) do |env:, status:, time:|
+ log_stop_request(env, status, time)
end
- rack_monitor.on(:error) do |id, payload|
- log_exception(payload[:exception], payload[:name])
+ rack_monitor.on(:error) do |exception:|
+ log_exception(exception)
end
end
- def log_exception(e, app_name)
+ def log_exception(e)
logger.error e.message
- logger.error filter_backtrace(e.backtrace, app_name).join("\n")
+ logger.error filter_backtrace(e.backtrace).join("\n")
end
def log_start_request(request)
info START_MSG % [
request[REQUEST_METHOD],
@@ -67,26 +65,27 @@
status
]
end
def log_request_params(request)
- with_http_params(request[QUERY_PARAMS]) do |params|
+ with_http_params(request[QUERY_STRING]) do |params|
info QUERY_MSG % [params.inspect]
end
end
def info(*args)
logger.info(*args)
end
def with_http_params(params)
params = ::Rack::Utils.parse_nested_query(params)
+
if params.size > 0
yield(filter_params(params))
end
end
- def filter_backtrace(backtrace, app_name)
+ def filter_backtrace(backtrace)
# TODO: what do we want to do with this?
backtrace.reject { |l| l.include?('gems') }
end
def filter_params(params)