2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

FIX: Ensure 100-logster initializer is run before 101-lograge (#12455)

The logster initializer tries to adds RailsMultisite::Formatter to the STDOUT logger. In production, the lograge initializer then removes the RailsMultisite:Formatter because the JSON log will include the database.

e10a74694a used `Rails.application.reloader.to_prepare` to defer running the 100-logster initializer, which meant it ran **after** 101-lograge. This meant that we were writing JSON logs with a non-json text prefix.

The `to_prepare` was added because our freedom-patches are now deferred using `to_prepare`, and some initializers were relying on the freedom patches. However, following 1533cbb38b, we decided to load the RailsMultisite freedom patch without `to_prepare`. Therefore, `005-site_settings` and `100-logster` no longer need to use `to_prepare`. Removing it means that these initializers are back to running in sequential order, and the logging issue will be resolved.

The only remaining initializer which depends on freedom patches is `100-i18n`. I've added a comment to explain why.
This commit is contained in:
David Taylor 2021-03-19 19:51:13 +00:00 committed by GitHub
parent e3d86c4e35
commit 374ab82dd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 151 additions and 154 deletions

View file

@ -16,7 +16,6 @@ if GlobalSetting.skip_redis?
return
end
Rails.application.reloader.to_prepare do
reload_settings = lambda {
RailsMultisite::ConnectionManagement.safe_each_connection do
begin
@ -38,4 +37,3 @@ Rails.application.reloader.to_prepare do
reload_settings.call
end
end
end

View file

@ -5,6 +5,7 @@
require 'i18n/backend/discourse_i18n'
require 'i18n/backend/fallback_locale_list'
# Requires the `translate_accelerator.rb` freedom patch to be loaded
Rails.application.reloader.to_prepare do
I18n.backend = I18n::Backend::DiscourseI18n.new
I18n.fallbacks = I18n::Backend::FallbackLocaleList.new

View file

@ -9,7 +9,6 @@ if GlobalSetting.skip_redis?
return
end
Rails.application.reloader.to_prepare do
if Rails.env.development? && RUBY_VERSION.match?(/^2\.5\.[23]/)
STDERR.puts "WARNING: Discourse development environment runs slower on Ruby 2.5.3 or below"
STDERR.puts "We recommend you upgrade to Ruby 2.6.1 for the optimal development performance"
@ -149,4 +148,3 @@ Rails.application.reloader.to_prepare do
url: plugin.metadata.url
}
end
end