Class: MicroserviceLogger
- Inherits:
-
Object
- Object
- MicroserviceLogger
- Defined in:
- lib/json_event_logger.rb,
lib/microservice_logging.rb
Overview
Log all the things in JSON
Constant Summary collapse
- DEFAULT_EVENT_TYPES =
[ :http_request, :applejack, :startup, :exception ].freeze
Instance Method Summary collapse
-
#initialize(service_name:, clock:, output:, scoped_properties: {}, events: DEFAULT_EVENT_TYPES) ⇒ MicroserviceLogger
constructor
A new instance of MicroserviceLogger.
- #method_missing(event) ⇒ Object
- #with(scoped_properties) ⇒ Object
Constructor Details
#initialize(service_name:, clock:, output:, scoped_properties: {}, events: DEFAULT_EVENT_TYPES) ⇒ MicroserviceLogger
Returns a new instance of MicroserviceLogger.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/microservice_logging.rb', line 8 def initialize(service_name:, clock:, output:, scoped_properties: {}, events: DEFAULT_EVENT_TYPES) @service_name = service_name @clock = clock @output = output @scoped_properties = scoped_properties @event_loggers = {} @events = events @events.each do |method_name| event_type = method_name.to_s @event_loggers[method_name] = JsonEventLogger.new(:service_name => @service_name, :clock => @clock, :output => @output, :scoped_properties => @scoped_properties, :event_type => event_type) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(event) ⇒ Object
30 31 32 33 |
# File 'lib/microservice_logging.rb', line 30 def method_missing(event) super unless @events.include? event @event_loggers[event] end |
Instance Method Details
#with(scoped_properties) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/microservice_logging.rb', line 42 def with(scoped_properties) MicroserviceLogger.new(:service_name => @service_name, :clock => @clock, :output => @output, :scoped_properties => scoped_properties) end |