@@ -18,6 +18,16 @@ module Sentry
1818 # request_id: "abc-123"
1919 # )
2020 #
21+ # @example With a message template
22+ # # Using positional parameters
23+ # Sentry.logger.info("User %s logged in", ["Jane Doe"])
24+ #
25+ # # Using hash parameters
26+ # Sentry.logger.info("User %{name} logged in", name: "Jane Doe")
27+ #
28+ # # Using hash parameters and extra attributes
29+ # Sentry.logger.info("User %{name} logged in", name: "Jane Doe", user_id: 312)
30+ #
2131 # @see https://develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
2232 class StructuredLogger
2333 # Severity number mapping for log levels according to the Sentry Logs Protocol
@@ -47,6 +57,7 @@ def initialize(config)
4757 # @param message [String] The log message
4858 # @param parameters [Array] Array of values to replace template parameters in the message
4959 # @param attributes [Hash] Additional attributes to include with the log
60+ #
5061 # @return [LogEvent, nil] The created log event or nil if logging is disabled
5162 def trace ( message , parameters = [ ] , **attributes )
5263 log ( __method__ , message , parameters : parameters , **attributes )
@@ -57,6 +68,7 @@ def trace(message, parameters = [], **attributes)
5768 # @param message [String] The log message
5869 # @param parameters [Array] Array of values to replace template parameters in the message
5970 # @param attributes [Hash] Additional attributes to include with the log
71+ #
6072 # @return [LogEvent, nil] The created log event or nil if logging is disabled
6173 def debug ( message , parameters = [ ] , **attributes )
6274 log ( __method__ , message , parameters : parameters , **attributes )
@@ -67,6 +79,7 @@ def debug(message, parameters = [], **attributes)
6779 # @param message [String] The log message
6880 # @param parameters [Array] Array of values to replace template parameters in the message
6981 # @param attributes [Hash] Additional attributes to include with the log
82+ #
7083 # @return [LogEvent, nil] The created log event or nil if logging is disabled
7184 def info ( message , parameters = [ ] , **attributes )
7285 log ( __method__ , message , parameters : parameters , **attributes )
@@ -77,6 +90,7 @@ def info(message, parameters = [], **attributes)
7790 # @param message [String] The log message
7891 # @param parameters [Array] Array of values to replace template parameters in the message
7992 # @param attributes [Hash] Additional attributes to include with the log
93+ #
8094 # @return [LogEvent, nil] The created log event or nil if logging is disabled
8195 def warn ( message , parameters = [ ] , **attributes )
8296 log ( __method__ , message , parameters : parameters , **attributes )
@@ -87,6 +101,7 @@ def warn(message, parameters = [], **attributes)
87101 # @param message [String] The log message
88102 # @param parameters [Array] Array of values to replace template parameters in the message
89103 # @param attributes [Hash] Additional attributes to include with the log
104+ #
90105 # @return [LogEvent, nil] The created log event or nil if logging is disabled
91106 def error ( message , parameters = [ ] , **attributes )
92107 log ( __method__ , message , parameters : parameters , **attributes )
@@ -97,6 +112,7 @@ def error(message, parameters = [], **attributes)
97112 # @param message [String] The log message
98113 # @param parameters [Array] Array of values to replace template parameters in the message
99114 # @param attributes [Hash] Additional attributes to include with the log
115+ #
100116 # @return [LogEvent, nil] The created log event or nil if logging is disabled
101117 def fatal ( message , parameters = [ ] , **attributes )
102118 log ( __method__ , message , parameters : parameters , **attributes )
@@ -108,6 +124,7 @@ def fatal(message, parameters = [], **attributes)
108124 # @param message [String] The log message
109125 # @param parameters [Array, Hash] Array or Hash of values to replace template parameters in the message
110126 # @param attributes [Hash] Additional attributes to include with the log
127+ #
111128 # @return [LogEvent, nil] The created log event or nil if logging is disabled
112129 def log ( level , message , parameters :, **attributes )
113130 if parameters . is_a? ( Hash ) && attributes . empty? && !message . include? ( "%" )
0 commit comments