class Sentry::StructuredLogger
@see develop.sentry.dev/sdk/telemetry/logs/ Sentry SDK Telemetry Logs Protocol
Sentry.logger.info(“User %{name} logged in”, name: “Jane Doe”, user_id: 312)
# Using hash parameters and extra attributes
Sentry.logger.info(“User %{name} logged in”, name: “Jane Doe”)
# Using hash parameters
Sentry.logger.info(“User %s logged in”, [“Jane Doe”])
# Using positional parameters
@example With a message template
)
request_id: “abc-123”
endpoint: “/api/users”,
status_code: 404,
Sentry.logger.warn(“API request failed”,
@example With structured data
Sentry.logger.info(“User logged in”, user_id: 123)
@example Basic usage
/
This class follows the Sentry Logs Protocol as defined in:
sending them to Sentry with structured data.
It provides methods for logging messages at different severity levels and
The StructuredLogger class implements Sentry’s SDK telemetry logs protocol.
def debug(message, parameters = [], **attributes)
-
(LogEvent, nil)- The created log event or nil if logging is disabled
Parameters:
-
attributes(Hash) -- Additional attributes to include with the log -
parameters(Array) -- Array of values to replace template parameters in the message -
message(String) -- The log message
def debug(message, parameters = [], **attributes) log(__method__, message, parameters: parameters, **attributes) end
def error(message, parameters = [], **attributes)
-
(LogEvent, nil)- The created log event or nil if logging is disabled
Parameters:
-
attributes(Hash) -- Additional attributes to include with the log -
parameters(Array) -- Array of values to replace template parameters in the message -
message(String) -- The log message
def error(message, parameters = [], **attributes) log(__method__, message, parameters: parameters, **attributes) end
def fatal(message, parameters = [], **attributes)
-
(LogEvent, nil)- The created log event or nil if logging is disabled
Parameters:
-
attributes(Hash) -- Additional attributes to include with the log -
parameters(Array) -- Array of values to replace template parameters in the message -
message(String) -- The log message
def fatal(message, parameters = [], **attributes) log(__method__, message, parameters: parameters, **attributes) end
def info(message, parameters = [], **attributes)
-
(LogEvent, nil)- The created log event or nil if logging is disabled
Parameters:
-
attributes(Hash) -- Additional attributes to include with the log -
parameters(Array) -- Array of values to replace template parameters in the message -
message(String) -- The log message
def info(message, parameters = [], **attributes) log(__method__, message, parameters: parameters, **attributes) end
def initialize(config)
-
config(Configuration) -- The Sentry configuration
def initialize(config) @config = config end
def log(level, message, parameters:, **attributes)
-
(LogEvent, nil)- The created log event or nil if logging is disabled
Parameters:
-
attributes(Hash) -- Additional attributes to include with the log -
parameters(Array, Hash) -- Array or Hash of values to replace template parameters in the message -
message(String) -- The log message -
level(Symbol) -- The log level (:trace, :debug, :info, :warn, :error, :fatal)
def log(level, message, parameters:, **attributes) case parameters when Array then Sentry.capture_log(message, level: level, severity: LEVELS[level], parameters: parameters, **attributes) else Sentry.capture_log(message, level: level, severity: LEVELS[level], **parameters) end end
def trace(message, parameters = [], **attributes)
-
(LogEvent, nil)- The created log event or nil if logging is disabled
Parameters:
-
attributes(Hash) -- Additional attributes to include with the log -
parameters(Array) -- Array of values to replace template parameters in the message -
message(String) -- The log message
def trace(message, parameters = [], **attributes) log(__method__, message, parameters: parameters, **attributes) end
def warn(message, parameters = [], **attributes)
-
(LogEvent, nil)- The created log event or nil if logging is disabled
Parameters:
-
attributes(Hash) -- Additional attributes to include with the log -
parameters(Array) -- Array of values to replace template parameters in the message -
message(String) -- The log message
def warn(message, parameters = [], **attributes) log(__method__, message, parameters: parameters, **attributes) end