Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'config/initializers/0_log_deprecations.rb')
-rw-r--r--config/initializers/0_log_deprecations.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/config/initializers/0_log_deprecations.rb b/config/initializers/0_log_deprecations.rb
new file mode 100644
index 00000000000..20fb5144937
--- /dev/null
+++ b/config/initializers/0_log_deprecations.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+def log_deprecations?
+ via_env_var = Gitlab::Utils.to_boolean(ENV['GITLAB_LOG_DEPRECATIONS'])
+ # enable by default during development unless explicitly turned off
+ via_env_var.nil? ? Rails.env.development? : via_env_var
+end
+
+if log_deprecations?
+ # Log deprecation warnings emitted through Kernel#warn, such as from gems or
+ # the Ruby VM.
+ Warning.process(/.+is deprecated$/) do |warning|
+ Gitlab::DeprecationJsonLogger.info(message: warning.strip, source: 'ruby')
+ # Returning :default means we continue emitting this to stderr as well.
+ :default
+ end
+
+ # Log deprecation warnings emitted from Rails (see ActiveSupport::Deprecation).
+ ActiveSupport::Notifications.subscribe('deprecation.rails') do |name, start, finish, id, payload|
+ Gitlab::DeprecationJsonLogger.info(message: payload[:message].strip, source: 'rails')
+ end
+end