Skip to content

Commit 5c5d0ee

Browse files
committed
Rename logger => sdk_logger
1 parent 60859d5 commit 5c5d0ee

25 files changed

+76
-61
lines changed

sentry-rails/lib/sentry/rails/configuration.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class Configuration
1717
if ::Rails.logger
1818
if defined?(::ActiveSupport::BroadcastLogger) && ::Rails.logger.is_a?(::ActiveSupport::BroadcastLogger)
1919
dupped_broadcasts = ::Rails.logger.broadcasts.map(&:dup)
20-
@logger = ::ActiveSupport::BroadcastLogger.new(*dupped_broadcasts)
20+
self.sdk_logger = ::ActiveSupport::BroadcastLogger.new(*dupped_broadcasts)
2121
else
22-
@logger = ::Rails.logger.dup
22+
self.sdk_logger = ::Rails.logger.dup
2323
end
2424
else
25-
@logger.warn(Sentry::LOGGER_PROGNAME) do
25+
sdk_logger.warn(Sentry::LOGGER_PROGNAME) do
2626
<<~MSG
2727
sentry-rails can't detect Rails.logger. it may be caused by misplacement of the SDK initialization code
2828
please make sure you place the Sentry.init block under the `config/initializers` folder, e.g. `config/initializers/sentry.rb`

sentry-rails/lib/sentry/rails/tracing/action_controller_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ActionControllerSubscriber < AbstractSubscriber
1414
SPAN_ORIGIN = "auto.view.rails"
1515

1616
def self.subscribe!
17-
Sentry.logger.warn <<~MSG
17+
Sentry.sdk_logger.warn <<~MSG
1818
DEPRECATION WARNING: sentry-rails has changed its approach on controller span recording and #{self.name} is now depreacted.
1919
Please stop using or referencing #{self.name} as it will be removed in the next major release.
2020
MSG

sentry-rails/spec/sentry/rails_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@
4444
describe "logger detection" do
4545
it "sets a duplicated Rails logger as the SDK's logger" do
4646
if Gem::Version.new(Rails.version) > Gem::Version.new("7.1.0.beta")
47-
expect(Sentry.configuration.logger).to be_a(ActiveSupport::BroadcastLogger)
47+
expect(Sentry.configuration.sdk_logger).to be_a(ActiveSupport::BroadcastLogger)
4848

49-
Sentry.configuration.logger.level = ::Logger::WARN
49+
Sentry.configuration.sdk_logger.level = ::Logger::WARN
5050

5151
# Configuring the SDK's logger should not affect the Rails logger
5252
expect(Rails.logger.broadcasts.first).to be_a(ActiveSupport::Logger)
5353
expect(Rails.logger.broadcasts.first.level).to eq(::Logger::DEBUG)
54-
expect(Sentry.configuration.logger.level).to eq(::Logger::WARN)
54+
expect(Sentry.configuration.sdk_logger.level).to eq(::Logger::WARN)
5555
else
56-
expect(Sentry.configuration.logger).to be_a(ActiveSupport::Logger)
56+
expect(Sentry.configuration.sdk_logger).to be_a(ActiveSupport::Logger)
5757

58-
Sentry.configuration.logger.level = ::Logger::WARN
58+
Sentry.configuration.sdk_logger.level = ::Logger::WARN
5959

6060
# Configuring the SDK's logger should not affect the Rails logger
6161
expect(Rails.logger.level).to eq(::Logger::DEBUG)
62-
expect(Sentry.configuration.logger.level).to eq(::Logger::WARN)
62+
expect(Sentry.configuration.sdk_logger.level).to eq(::Logger::WARN)
6363
end
6464
end
6565

@@ -70,15 +70,15 @@
7070
config.logger = logger
7171
end
7272

73-
expect(Sentry.configuration.logger).to eq(logger)
73+
expect(Sentry.configuration.sdk_logger).to eq(logger)
7474
end
7575

7676
it "doesn't cause error if Rails::Logger is not present during SDK initialization" do
7777
Rails.logger = nil
7878

7979
Sentry.init
8080

81-
expect(Sentry.configuration.logger).to be_a(Sentry::Logger)
81+
expect(Sentry.configuration.sdk_logger).to be_a(Sentry::Logger)
8282
end
8383
end
8484

sentry-ruby/lib/sentry-ruby.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ def exception_locals_tp
9494
# @return [Metrics::Aggregator, nil]
9595
attr_reader :metrics_aggregator
9696

97+
# @!attribute [r] logger
98+
# @return [Logger]
99+
# @!visibility private
100+
attr_reader :sdk_logger
101+
97102
##### Patch Registration #####
98103

99104
# @!visibility private
@@ -138,7 +143,7 @@ def integrations
138143
# @param version [String] version of the integration
139144
def register_integration(name, version)
140145
if initialized?
141-
logger.warn(LOGGER_PROGNAME) do
146+
sdk_logger.warn(LOGGER_PROGNAME) do
142147
<<~MSG
143148
Integration '#{name}' is loaded after the SDK is initialized, which can cause unexpected behavior. Please make sure all integrations are loaded before SDK initialization.
144149
MSG
@@ -238,6 +243,10 @@ def add_attachment(**opts)
238243
def init(&block)
239244
config = Configuration.new
240245
yield(config) if block_given?
246+
247+
# Internal SDK logger
248+
@sdk_logger = config.sdk_logger
249+
241250
config.detect_release
242251
apply_patches(config)
243252
config.validate
@@ -615,11 +624,6 @@ def sys_command(command)
615624
result.strip
616625
end
617626

618-
# @!visibility private
619-
def logger
620-
configuration.logger
621-
end
622-
623627
# @!visibility private
624628
def sdk_meta
625629
META

sentry-ruby/lib/sentry/background_worker.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class BackgroundWorker
99
include LoggingHelper
1010

1111
attr_reader :max_queue, :number_of_threads
12-
# @deprecated Use Sentry.logger to retrieve the current logger instead.
12+
# @deprecated Use Sentry.sdk_logger to retrieve the current logger instead.
1313
attr_reader :logger
1414
attr_accessor :shutdown_timeout
1515

@@ -19,7 +19,7 @@ def initialize(configuration)
1919
@shutdown_timeout = 1
2020
@number_of_threads = configuration.background_worker_threads
2121
@max_queue = configuration.background_worker_max_queue
22-
@logger = configuration.logger
22+
@logger = configuration.sdk_logger
2323
@debug = configuration.debug
2424
@shutdown_callback = nil
2525

sentry-ruby/lib/sentry/backpressure_monitor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class BackpressureMonitor < ThreadedPeriodicWorker
66
MAX_DOWNSAMPLE_FACTOR = 10
77

88
def initialize(configuration, client, interval: DEFAULT_INTERVAL)
9-
super(configuration.logger, interval)
9+
super(configuration.sdk_logger, interval)
1010
@client = client
1111

1212
@healthy = true

sentry-ruby/lib/sentry/breadcrumb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def serialized_data
6363
begin
6464
::JSON.parse(::JSON.generate(@data, max_nesting: MAX_NESTING))
6565
rescue Exception => e
66-
Sentry.logger.debug(LOGGER_PROGNAME) do
66+
Sentry.sdk_logger.debug(LOGGER_PROGNAME) do
6767
<<~MSG
6868
can't serialize breadcrumb data because of error: #{e}
6969
data: #{@data}

sentry-ruby/lib/sentry/client.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ class Client
1919
# @!macro configuration
2020
attr_reader :configuration
2121

22-
# @deprecated Use Sentry.logger to retrieve the current logger instead.
23-
attr_reader :logger
22+
attr_reader :log_event_buffer
2423

2524
# @param configuration [Configuration]
2625
def initialize(configuration)
2726
@configuration = configuration
28-
@logger = configuration.logger
27+
@logger = configuration.sdk_logger
2928

3029
if transport_class = configuration.transport.transport_class
3130
@transport = transport_class.new(configuration)

sentry-ruby/lib/sentry/configuration.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ def capture_exception_frame_locals=(value)
184184
# Logger used by Sentry. In Rails, this is the Rails logger, otherwise
185185
# Sentry provides its own Sentry::Logger.
186186
# @return [Logger]
187-
attr_accessor :logger
187+
attr_accessor :sdk_logger
188+
alias_method :logger, :sdk_logger
189+
alias_method :logger=, :sdk_logger=
188190

189191
# Project directory root for in_app detection. Could be Rails root, etc.
190192
# Set automatically for Rails.
@@ -312,6 +314,10 @@ def capture_exception_frame_locals=(value)
312314
# @return [Integer]
313315
attr_accessor :max_log_events
314316

317+
# Experimental features configuration
318+
# @return [Hash]
319+
attr_accessor :_experiments
320+
315321
# these are not config options
316322
# @!visibility private
317323
attr_reader :errors, :gem_specs
@@ -424,7 +430,7 @@ def initialize
424430
self.excluded_exceptions = IGNORE_DEFAULT + PUMA_IGNORE_DEFAULT
425431
self.inspect_exception_causes_for_exclusion = true
426432
self.linecache = ::Sentry::LineCache.new
427-
self.logger = ::Sentry::Logger.new(STDOUT)
433+
self.sdk_logger = ::Sentry::Logger.new(STDOUT)
428434
self.project_root = Dir.pwd
429435
self.propagate_traces = true
430436

@@ -458,6 +464,7 @@ def initialize
458464
@cron = Cron::Configuration.new
459465
@metrics = Metrics::Configuration.new
460466
@gem_specs = Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map)
467+
@_experiments = { enable_logs: false }
461468

462469
run_post_initialization_callbacks
463470

sentry-ruby/lib/sentry/interfaces/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def filter_and_format_headers(env, send_default_pii)
9999
# Rails adds objects to the Rack env that can sometimes raise exceptions
100100
# when `to_s` is called.
101101
# See: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/remote_ip.rb#L134
102-
Sentry.logger.warn(LOGGER_PROGNAME) { "Error raised while formatting headers: #{e.message}" }
102+
Sentry.sdk_logger.warn(LOGGER_PROGNAME) { "Error raised while formatting headers: #{e.message}" }
103103
next
104104
end
105105
end

0 commit comments

Comments
 (0)