Class: SemanticLogger::Appender::NewRelic
- Defined in:
- lib/semantic_logger/appender/new_relic.rb
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Base
Instance Method Summary collapse
-
#default_formatter ⇒ Object
Returns [Hash] of parameters to send to New Relic.
-
#initialize(level = :error, &block) ⇒ NewRelic
constructor
Allow the level for this appender to be overwritten Default: :error Note: Not recommended to set the log level to :info, :debug, or :trace as that would flood NewRelic with Error notices.
-
#log(log) ⇒ Object
Send an error notification to New Relic.
Methods inherited from Base
colorized_formatter, #flush, #level
Methods inherited from Base
#benchmark, default_level, default_level=, #level, #level=, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload
Constructor Details
#initialize(level = :error, &block) ⇒ NewRelic
Allow the level for this appender to be overwritten
Default: :error
Note: Not recommended to set the log level to :info, :debug, or :trace as that would flood NewRelic with Error notices
65 66 67 |
# File 'lib/semantic_logger/appender/new_relic.rb', line 65 def initialize(level=:error, &block) super(level, &block) end |
Instance Method Details
#default_formatter ⇒ Object
Returns [Hash] of parameters to send to New Relic.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/semantic_logger/appender/new_relic.rb', line 70 def default_formatter Proc.new do |log| custom_params = {thread_name: log.thread_name} custom_params[:duration] = "#{log.duration} ms" if log.duration custom_params[:payload] = log.payload if log.payload custom_params[:tags] = log. if log. && (log..size > 0) custom_params[:message] = log. if log.exception {metric: log.metric, custom_params: custom_params} end end |
#log(log) ⇒ Object
Send an error notification to New Relic
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/semantic_logger/appender/new_relic.rb', line 83 def log(log) # Ensure minimum log level is met, and check filter return false if (level_index > (log.level_index || 0)) || !(log) # Send error messages as Runtime exceptions exception = if log.exception log.exception else error = RuntimeError.new(log.) error.set_backtrace(log.backtrace) if log.backtrace error end # For more documentation on the NewRelic::Agent.notice_error method see: # http://rubydoc.info/github/newrelic/rpm/NewRelic/Agent#notice_error-instance_method # and https://docs.newrelic.com/docs/ruby/ruby-agent-api NewRelic::Agent.notice_error(exception, formatter.call(log)) true end |