Class: Appsignal::EventFormatter Private
- Defined in:
- lib/appsignal/event_formatter.rb,
lib/appsignal/event_formatter/rom/sql_formatter.rb,
lib/appsignal/event_formatter/sequel/sql_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.
Defined Under Namespace
Modules: ActionView, ActiveRecord, ElasticSearch, Faraday, MongoRubyDriver, Rom, Sequel
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
- .register(name, formatter = nil) ⇒ 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.
52 53 54 55 |
# File 'lib/appsignal/event_formatter.rb', line 52 def format(name, payload) formatter = formatters[name] formatter&.format(payload) 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.
21 22 23 |
# File 'lib/appsignal/event_formatter.rb', line 21 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.
17 18 19 |
# File 'lib/appsignal/event_formatter.rb', line 17 def formatters @formatters ||= {} end |
.register(name, formatter = nil) ⇒ 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.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/appsignal/event_formatter.rb', line 25 def register(name, formatter = nil) if registered?(name, formatter) logger.warn( "Formatter for '#{name}' already registered, not registering " \ "'#{formatter.name}'" ) return end initialize_formatter 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.
44 45 46 47 48 49 50 |
# File 'lib/appsignal/event_formatter.rb', line 44 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.
37 38 39 40 41 42 |
# File 'lib/appsignal/event_formatter.rb', line 37 def unregister(name, formatter = self) return unless formatter_classes[name] == formatter formatter_classes.delete(name) formatters.delete(name) end |