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.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoints = {}) ⇒ StructuredEventLogger

Returns a new instance of StructuredEventLogger.



20
21
22
23
24
25
26
27
# File 'lib/structured_event_logger.rb', line 20

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.



18
19
20
# File 'lib/structured_event_logger.rb', line 18

def error_handler
  @error_handler
end

#onlyObject

Returns the value of attribute only.



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

def only
  @only
end

Instance Method Details

#contextObject



36
37
38
# File 'lib/structured_event_logger.rb', line 36

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

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



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

def event(scope, event, content = {})
  return unless @only.nil? || @only.call(scope, event, content)
  log_event scope, event, flatten_hash(content)
rescue EventHandlingException => e
  error_handler.call(e)
end