"Fossies" - the Fresh Open Source Software Archive 
Member "discourse-2.8.3/config/initializers/100-logster.rb" (14 Apr 2022, 5247 Bytes) of package /linux/www/discourse-2.8.3.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "100-logster.rb":
2.7.13_vs_2.8.0.
1 # frozen_string_literal: true
2
3 if GlobalSetting.skip_redis?
4 Rails.application.reloader.to_prepare do
5 if Rails.logger.respond_to? :chained
6 Rails.logger = Rails.logger.chained.first
7 end
8 end
9 return
10 end
11
12 if Rails.env.development? && RUBY_VERSION.match?(/^2\.5\.[23]/)
13 STDERR.puts "WARNING: Discourse development environment runs slower on Ruby 2.5.3 or below"
14 STDERR.puts "We recommend you upgrade to Ruby 2.6.1 for the optimal development performance"
15
16 # we have to used to older and slower version of the logger cause the new one exposes a Ruby bug in
17 # the Queue class which causes segmentation faults
18 Logster::Scheduler.disable
19 end
20
21 if Rails.env.development? && !Sidekiq.server? && ENV["RAILS_LOGS_STDOUT"] == "1"
22 Rails.application.config.after_initialize do
23 console = ActiveSupport::Logger.new(STDOUT)
24 original_logger = Rails.logger.chained.first
25 console.formatter = original_logger.formatter
26 console.level = original_logger.level
27
28 unless ActiveSupport::Logger.logger_outputs_to?(original_logger, STDOUT)
29 original_logger.extend(ActiveSupport::Logger.broadcast(console))
30 end
31 end
32 end
33
34 if Rails.env.production?
35 Logster.store.ignore = [
36 # These errors are caused by client requests. No need to log them.
37 # Rails itself defines these as 'silent exceptions', but this does
38 # not entirely prevent them from being logged
39 # https://github.com/rails/rails/blob/f2caed1e/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb#L39-L42
40 /^ActionController::RoutingError \(No route matches/,
41 /^ActionDispatch::Http::MimeNegotiation::InvalidType/,
42
43 /^PG::Error: ERROR:\s+duplicate key/,
44
45 /^ActionController::UnknownFormat/,
46 /^ActionController::UnknownHttpMethod/,
47 /^AbstractController::ActionNotFound/,
48 # ignore any empty JS errors that contain blanks or zeros for line and column fields
49 #
50 # Line:
51 # Column:
52 #
53 /(?m).*?Line: (?:\D|0).*?Column: (?:\D|0)/,
54
55 # suppress empty JS errors (covers MSIE 9, etc)
56 /^(Syntax|Script) error.*Line: (0|1)\b/m,
57
58 # CSRF errors are not providing enough data
59 # suppress unconditionally for now
60 /^Can't verify CSRF token authenticity.$/,
61
62 # Yandex bot triggers this JS error a lot
63 /^Uncaught ReferenceError: I18n is not defined/,
64
65 # related to browser plugins somehow, we don't care
66 /Error calling method on NPObject/,
67
68 # 404s can be dealt with elsewhere
69 /^ActiveRecord::RecordNotFound/,
70
71 # bad asset requested, no need to log
72 /^ActionController::BadRequest/,
73
74 # we can't do anything about invalid parameters
75 /Rack::QueryParser::InvalidParameterError/,
76
77 # we handle this cleanly in the message bus middleware
78 # no point logging to logster
79 /RateLimiter::LimitExceeded.*/m,
80 ]
81 Logster.config.env_expandable_keys.push(:hostname, :problem_db)
82 end
83
84 Logster.store.max_backlog = GlobalSetting.max_logster_logs
85
86 # TODO logster should be able to do this automatically
87 Logster.config.subdirectory = "#{GlobalSetting.relative_url_root}/logs"
88
89 Logster.config.application_version = Discourse.git_version
90 Logster.config.enable_custom_patterns_via_ui = true
91 Logster.config.use_full_hostname = true
92 Logster.config.enable_js_error_reporting = GlobalSetting.enable_js_error_reporting
93
94 store = Logster.store
95 redis = Logster.store.redis
96 store.redis_prefix = Proc.new { redis.namespace }
97 store.redis_raw_connection = redis.without_namespace
98 severities = [Logger::WARN, Logger::ERROR, Logger::FATAL, Logger::UNKNOWN]
99
100 RailsMultisite::ConnectionManagement.each_connection do
101 error_rate_per_minute = SiteSetting.alert_admins_if_errors_per_minute rescue 0
102
103 if (error_rate_per_minute || 0) > 0
104 store.register_rate_limit_per_minute(severities, error_rate_per_minute) do |rate|
105 MessageBus.publish("/logs_error_rate_exceeded",
106 {
107 rate: rate,
108 duration: 'minute',
109 publish_at: Time.current.to_i
110 },
111 group_ids: [Group::AUTO_GROUPS[:admins]]
112 )
113 end
114 end
115
116 error_rate_per_hour = SiteSetting.alert_admins_if_errors_per_hour rescue 0
117
118 if (error_rate_per_hour || 0) > 0
119 store.register_rate_limit_per_hour(severities, error_rate_per_hour) do |rate|
120 MessageBus.publish("/logs_error_rate_exceeded",
121 {
122 rate: rate,
123 duration: 'hour',
124 publish_at: Time.current.to_i,
125 },
126 group_ids: [Group::AUTO_GROUPS[:admins]]
127 )
128 end
129 end
130 end
131
132 if Rails.configuration.multisite
133 if Rails.logger.respond_to? :chained
134 chained = Rails.logger.chained
135 chained && chained.first.formatter = RailsMultisite::Formatter.new
136 end
137 end
138
139 Logster.config.project_directories = [
140 { path: Rails.root.to_s, url: "https://github.com/discourse/discourse", main_app: true }
141 ]
142 Discourse.plugins.each do |plugin|
143 next if !plugin.metadata.url
144
145 Logster.config.project_directories << {
146 path: "#{Rails.root.to_s}/plugins/#{plugin.directory_name}",
147 url: plugin.metadata.url
148 }
149 end