lib/semantic_logger/appender/sentry.rb in semantic_logger-4.1.0 vs lib/semantic_logger/appender/sentry.rb in semantic_logger-4.1.1
- old
+ new
@@ -34,28 +34,31 @@
#
# application: [String]
# Name of this application to appear in log messages.
# Default: SemanticLogger.application
def initialize(level: :error, formatter: nil, filter: nil, application: nil, host: nil, &block)
+ # Replace the Sentry Raven logger so that we can identify its log messages and not forward them to Sentry
+ Raven.configure { |config| config.logger = SemanticLogger[Raven] }
super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
end
# Send an error notification to sentry
def log(log)
return false unless should_log?(log)
+ # Ignore logs coming from Ravent itself
+ return false if log.name == 'Raven'
context = formatter.call(log, self)
if log.exception
context.delete(:exception)
Raven.capture_exception(log.exception, context)
else
- message = {
- error_class: context.delete(:name),
- error_message: context.delete(:message),
- extra: context
+ attrs = {
+ level: context.delete(:level),
+ extra: context
}
- message[:backtrace] = log.backtrace if log.backtrace
- Raven.capture_message(message[:error_message], message)
+ attrs[:extra][:backtrace] = log.backtrace if log.backtrace
+ Raven.capture_message(context[:message], attrs)
end
true
end
private