@@ -95,27 +95,6 @@ def exception_locals_tp
9595 # @return [Metrics::Aggregator, nil]
9696 attr_reader :metrics_aggregator
9797
98- # @!attribute [r] logger
99- # Returns the structured logger instance that implements Sentry's SDK telemetry logs protocol.
100- # This logger is only available when logs are enabled in the configuration.
101- #
102- # @example Enable logs in configuration
103- # Sentry.init do |config|
104- # config.dsn = "YOUR_DSN"
105- # config.enable_logs = true
106- # end
107- #
108- # @example Basic usage
109- # Sentry.logger.info("User logged in successfully", user_id: 123)
110- # Sentry.logger.error("Failed to process payment",
111- # transaction_id: "tx_123",
112- # error_code: "PAYMENT_FAILED"
113- # )
114- #
115- # @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
116- # @return [StructuredLogger, nil] The structured logger instance or nil if logs are disabled
117- attr_reader :logger
118-
11998 ##### Patch Registration #####
12099
121100 # @!visibility private
@@ -261,11 +240,6 @@ def init(&block)
261240 config = Configuration . new
262241 yield ( config ) if block_given?
263242
264- # Initialize the public-facing Structured Logger if logs are enabled
265- # This creates a StructuredLogger instance that implements Sentry's SDK telemetry logs protocol
266- # @see https://develop.sentry.dev/sdk/telemetry/logs/
267- @logger = StructuredLogger . new ( config ) if config . enable_logs
268-
269243 config . detect_release
270244 apply_patches ( config )
271245 config . validate
@@ -640,18 +614,45 @@ def continue_trace(env, **options)
640614 get_current_hub . continue_trace ( env , **options )
641615 end
642616
643- ##### Helpers #####
644-
645- # @!visibility private
617+ # Returns the structured logger instance that implements Sentry's SDK telemetry logs protocol.
618+ #
619+ # This logger is only available when logs are enabled in the configuration.
620+ #
621+ # @example Enable logs in configuration
622+ # Sentry.init do |config|
623+ # config.dsn = "YOUR_DSN"
624+ # config.enable_logs = true
625+ # end
626+ #
627+ # @example Basic usage
628+ # Sentry.logger.info("User logged in successfully", user_id: 123)
629+ # Sentry.logger.error("Failed to process payment",
630+ # transaction_id: "tx_123",
631+ # error_code: "PAYMENT_FAILED"
632+ # )
633+ #
634+ # @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
635+ #
636+ # @return [StructuredLogger, nil] The structured logger instance or nil if logs are disabled
646637 def logger
647- warn <<~STR
648- [sentry] `Sentry.logger` will no longer be used as internal SDK logger when `enable_logs` feature is turned on.
649- Use Sentry.configuration.sdk_logger for SDK-specific logging needs."
650- STR
651-
652- configuration . sdk_logger
638+ @logger ||=
639+ if configuration . enable_logs
640+ # Initialize the public-facing Structured Logger if logs are enabled
641+ # This creates a StructuredLogger instance that implements Sentry's SDK telemetry logs protocol
642+ # @see https://develop.sentry.dev/sdk/telemetry/logs/
643+ StructuredLogger . new ( configuration )
644+ else
645+ warn <<~STR
646+ [sentry] `Sentry.logger` will no longer be used as internal SDK logger when `enable_logs` feature is turned on.
647+ Use Sentry.configuration.sdk_logger for SDK-specific logging needs."
648+ STR
649+
650+ configuration . sdk_logger
651+ end
653652 end
654653
654+ ##### Helpers #####
655+
655656 # @!visibility private
656657 def sys_command ( command )
657658 result = `#{ command } 2>&1` rescue nil
0 commit comments