diff options
Diffstat (limited to 'config/initializers/error_log.rb')
| -rw-r--r-- | config/initializers/error_log.rb | 20 |
1 files changed, 20 insertions, 0 deletions
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 @@ | |||
| 1 | # Every controller-level exception (the 500s) in one lean file, | ||
| 2 | # independent of the base log level -- log/production.log can stay | ||
| 3 | # quiet without losing error visibility. | ||
| 4 | if Rails.env.production? | ||
| 5 | error_logger = ActiveSupport::Logger.new(Rails.root.join("log", "errors.log")) | ||
| 6 | |||
| 7 | ActiveSupport::Notifications.subscribe("process_action.action_controller") do |*, payload| | ||
| 8 | if (exception = payload[:exception_object]) | ||
| 9 | status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception.class.name) | ||
| 10 | next if status < 500 | ||
| 11 | |||
| 12 | error_logger.error( | ||
| 13 | "#{Time.now.iso8601} [#{status}] #{payload[:controller]}##{payload[:action]} #{payload[:path]} " \ | ||
| 14 | "-- #{exception.class}: #{exception.message}\n " + | ||
| 15 | Array(exception.backtrace).first(5).join("\n ") | ||
| 16 | ) | ||
| 17 | end | ||
| 18 | end | ||
| 19 | end | ||
| 20 | |||
