Class: Appsignal::EventFormatter
- 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/view_component/render_formatter.rb,
lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb,
lib/appsignal/event_formatter/active_record/instantiation_formatter.rb
Overview
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, ViewComponent
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
- .registered?(name, klass = nil) ⇒ Boolean
- .unregister(name, formatter = self) ⇒ Object
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.
53 54 55 56 |
# File 'lib/appsignal/event_formatter.rb', line 53 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.
16 17 18 |
# File 'lib/appsignal/event_formatter.rb', line 16 def formatters @formatters ||= {} end |
.register(name, formatter = nil) ⇒ Object
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
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
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 |