Class: StructuredEventLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/structured_event_logger.rb,
lib/structured_event_logger/version.rb

Defined Under Namespace

Classes: Error, EventHandlingException, HumanReadableLogger, JsonWriter, Syslogger

Constant Summary collapse

VERSION =
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoints = {}) ⇒ StructuredEventLogger

Returns a new instance of StructuredEventLogger.



18
19
20
21
22
23
24
# File 'lib/structured_event_logger.rb', line 18

def initialize(endpoints = {})
  @endpoints = endpoints

  @thread_contexts = {}
  @default_context = {}
  @error_handler = lambda { |exception| raise(exception) }
end

Instance Attribute Details

#default_contextObject (readonly)

Returns the value of attribute default_context.



15
16
17
# File 'lib/structured_event_logger.rb', line 15

def default_context
  @default_context
end

#endpointsObject (readonly)

Returns the value of attribute endpoints.



15
16
17
# File 'lib/structured_event_logger.rb', line 15

def endpoints
  @endpoints
end

#error_handlerObject

Returns the value of attribute error_handler.



16
17
18
# File 'lib/structured_event_logger.rb', line 16

def error_handler
  @error_handler
end

Instance Method Details

#contextObject



32
33
34
# File 'lib/structured_event_logger.rb', line 32

def context
  @thread_contexts[thread_key] ||= {}
end

#event(scope, event, content = {}) ⇒ Object



26
27
28
29
30
# File 'lib/structured_event_logger.rb', line 26

def event(scope, event, content = {})
  log_event scope, event, flatten_hash(content)
rescue EventHandlingException => e
  error_handler.call(e)
end