diff --git a/README.md b/README.md index 177d02c..9a8c89b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ ## Interesting Gems to try out +* [ ] ViewComponent ?? +* [ ] Devise Vs Authentication-Zero * [ ] Devise * [ ] **Noticed** * [ ] CANCANCAN diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 83d4bf7..1e9b560 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,8 +2,15 @@ class ApplicationController < ActionController::Base MAX_DURATION_TO_COMPLETE_IN_SECONDS = 3 around_action do |_, action| - logger.measure_error "Took too long to complete, please review your code as asynchronous task", min_duration: MAX_DURATION_TO_COMPLETE_IN_SECONDS * 1000 do + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + begin action.call + ensure + ActionView::Base.logger.level = :info + duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start + if duration > MAX_DURATION_TO_COMPLETE_IN_SECONDS + logger.warn("processing took too long to complete, please review your code as asynchronous job!", duration: duration * 1_000) + end end end end diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 8bd6bbe..acc025c 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -8,6 +8,8 @@ class MainController < ApplicationController logger.info "line1\nline2\nline3" logger.warn "a warning" logger.error "an error" + + # raise "this is an error" sleep 3 end end diff --git a/config/environments/production.rb b/config/environments/production.rb index cd9eaa8..9d270db 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -92,6 +92,5 @@ Rails.application.configure do config.active_record.dump_schema_after_migration = false # Semantic Logger in console log only! - require_relative "../../lib/formatters/basic_formatter" config.semantic_logger.add_appender(file_name: "log/production.log", formatter: BasicFormatter.new) end diff --git a/lib/formatters/basic_formatter.rb b/lib/formatters/basic_formatter.rb index 11e93bd..83bc020 100644 --- a/lib/formatters/basic_formatter.rb +++ b/lib/formatters/basic_formatter.rb @@ -75,7 +75,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color if @time_format [time, level, process_info, tags, named_tags, duration, name, message, payload, exception].compact.join(" ") else - [level, process_info, tags, named_tags, duration, name, message, payload, exception].compact.join(" ") + [tags, named_tags, duration, name, message, payload, exception].compact.join(" ") end end end