From bb1eaeec603ce6eedf6429100ee8634586a5586e Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 19 Jul 2026 01:51:34 +0200 Subject: Add the error log writer --- config/initializers/error_log.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 config/initializers/error_log.rb (limited to 'config/initializers/error_log.rb') diff --git a/config/initializers/error_log.rb b/config/initializers/error_log.rb new file mode 100644 index 0000000..74117cb --- /dev/null +++ b/config/initializers/error_log.rb @@ -0,0 +1,20 @@ +# Every controller-level exception (the 500s) in one lean file, +# independent of the base log level -- log/production.log can stay +# quiet without losing error visibility. +if Rails.env.production? + error_logger = ActiveSupport::Logger.new(Rails.root.join("log", "errors.log")) + + ActiveSupport::Notifications.subscribe("process_action.action_controller") do |*, payload| + if (exception = payload[:exception_object]) + status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception.class.name) + next if status < 500 + + error_logger.error( + "#{Time.now.iso8601} [#{status}] #{payload[:controller]}##{payload[:action]} #{payload[:path]} " \ + "-- #{exception.class}: #{exception.message}\n " + + Array(exception.backtrace).first(5).join("\n ") + ) + end + end +end + -- cgit v1.3