Class: Appsignal::EventFormatter Private
- Defined in:
- lib/appsignal/event_formatter.rb,
lib/appsignal/event_formatter/moped/query_formatter.rb,
lib/appsignal/event_formatter/faraday/request_formatter.rb,
lib/appsignal/event_formatter/active_record/sql_formatter.rb,
lib/appsignal/event_formatter/action_view/render_formatter.rb,
lib/appsignal/event_formatter/elastic_search/search_formatter.rb,
lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb,
lib/appsignal/event_formatter/active_record/instantiation_formatter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Keeps track of formatters for types event that we can use to get the title and body of an event. Formatters should inherit from this class and implement a format(payload) method which returns an array with the title and body.
When implementing a formatter remember that it cannot keep separate state per event, the same object will be called intermittently in a threaded environment. So only keep global configuration as state and pass the payload around as an argument if you need to use helper methods.
Direct Known Subclasses
ActionView::RenderFormatter, ActiveRecord::InstantiationFormatter, ActiveRecord::SqlFormatter, ElasticSearch::SearchFormatter, Faraday::RequestFormatter, Moped::QueryFormatter
Defined Under Namespace
Modules: ActionView, ActiveRecord, ElasticSearch, Faraday, MongoRubyDriver, Moped
Constant Summary collapse
- DEFAULT =
0
- SQL_BODY_FORMAT =
1
Class Method Summary collapse
- .format(name, payload) ⇒ Object private
- .formatter_classes ⇒ Object private
- .formatters ⇒ Object private
- .initialize_formatters ⇒ Object private
- .register(name, formatter = self) ⇒ Object private
- .registered?(name, klass = nil) ⇒ Boolean private
- .unregister(name, formatter = self) ⇒ Object private
Class Method Details
.format(name, payload) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 62 |
# File 'lib/appsignal/event_formatter.rb', line 59 def format(name, payload) formatter = formatters[name] formatter.format(payload) unless formatter.nil? end |
.formatter_classes ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/appsignal/event_formatter.rb', line 19 def formatter_classes @@formatter_classes ||= {} end |
.formatters ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/appsignal/event_formatter.rb', line 15 def formatters @@formatters ||= {} end |
.initialize_formatters ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/appsignal/event_formatter.rb', line 42 def initialize_formatters formatter_classes.each do |name, formatter| begin format_method = formatter.instance_method(:format) if format_method && format_method.arity == 1 formatters[name] = formatter.new else raise "#{f} does not have a format(payload) method" end rescue => ex formatter_classes.delete(name) formatters.delete(name) Appsignal.logger.debug("'#{ex.}' when initializing #{name} event formatter") end end end |
.register(name, formatter = self) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 |
# File 'lib/appsignal/event_formatter.rb', line 23 def register(name, formatter = self) formatter_classes[name] = formatter end |
.registered?(name, klass = nil) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 |
# File 'lib/appsignal/event_formatter.rb', line 34 def registered?(name, klass = nil) if klass formatter_classes[name] == klass else formatter_classes.include?(name) end end |
.unregister(name, formatter = self) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 32 |
# File 'lib/appsignal/event_formatter.rb', line 27 def unregister(name, formatter = self) return unless formatter_classes[name] == formatter formatter_classes.delete(name) formatters.delete(name) end |