From dd7771c59d4b08476e157b5ae7e8d40587c74e11 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Thu, 23 Jul 2015 16:51:32 +0300 Subject: [PATCH] Log all activerecord and activemodel user issues #2808 --- app/models/epp/domain.rb | 1 - config/initializers/eis_custom_active_model.rb | 18 ++++++++++++++++++ .../initializers/eis_custom_active_record.rb | 7 +++++++ config/initializers/eis_custom_flash.rb | 1 + config/unicorn.rb | 1 - 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 config/initializers/eis_custom_active_model.rb create mode 100644 config/initializers/eis_custom_active_record.rb diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 37cbbfa75..57cd1b5a3 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -134,7 +134,6 @@ class Epp::Domain < Domain at[:reserved_pw] = frame.css('reserved > pw').text # at[:statuses] = domain_statuses_attrs(frame, action) - # binding.pry at[:nameservers_attributes] = nameservers_attrs(frame, action) at[:admin_domain_contacts_attributes] = admin_domain_contacts_attrs(frame, action) at[:tech_domain_contacts_attributes] = tech_domain_contacts_attrs(frame, action) diff --git a/config/initializers/eis_custom_active_model.rb b/config/initializers/eis_custom_active_model.rb new file mode 100644 index 000000000..e5ea5b2b3 --- /dev/null +++ b/config/initializers/eis_custom_active_model.rb @@ -0,0 +1,18 @@ +# Log all active model user errors +module ActiveModel + class Errors + def add(attribute, message = :invalid, options = {}) + message = normalize_message(attribute, message, options) + if exception = options[:strict] + exception = ActiveModel::StrictValidationFailed if exception == true + raise exception, full_message(attribute, message) + end + + # CUSTOM logging + Rails.logger.info "USER MSG: #{Time.now.to_s(:db)} ACTIVEMODEL: #{@base.try(:class)} [#{attribute}] #{message}" if message.present? + # END of CUSTOM logging + + self[attribute] << message + end + end +end diff --git a/config/initializers/eis_custom_active_record.rb b/config/initializers/eis_custom_active_record.rb new file mode 100644 index 000000000..142d3b8f4 --- /dev/null +++ b/config/initializers/eis_custom_active_record.rb @@ -0,0 +1,7 @@ +# Log all user issues raised by active record +class ActiveRecord::Base + after_validation do |m| + Rails.logger.info "USER MSG: #{Time.now.to_s(:db)} ACTIVERECORD: #{m.class} ##{m.id} #{m.errors.full_messages} #{m.errors['epp_errors']}" if m.errors.present? + true + end +end diff --git a/config/initializers/eis_custom_flash.rb b/config/initializers/eis_custom_flash.rb index 846d46bd5..d9694cf99 100644 --- a/config/initializers/eis_custom_flash.rb +++ b/config/initializers/eis_custom_flash.rb @@ -1,3 +1,4 @@ +# Log all flash messages module ActionDispatch class Flash def call(env) diff --git a/config/unicorn.rb b/config/unicorn.rb index 350bc5ed1..0e6d8d383 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -1,7 +1,6 @@ worker_processes 2 # after_fork do |server, worker| - # binding.pry # ActiveRecord::Base.establish_connection # Que.mode = :async