Class: StructuredEventLogger

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

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_logger, unstructured_logger = nil) ⇒ StructuredEventLogger

Returns a new instance of StructuredEventLogger.



8
9
10
11
# File 'lib/structured_event_logger.rb', line 8

def initialize(json_logger, unstructured_logger = nil)
  @json_logger, @unstructured_logger = json_logger, unstructured_logger
  @thread_contexts = {}
end

Instance Attribute Details

#json_loggerObject (readonly)

Returns the value of attribute json_logger.



6
7
8
# File 'lib/structured_event_logger.rb', line 6

def json_logger
  @json_logger
end

#unstructured_loggerObject (readonly)

Returns the value of attribute unstructured_logger.



6
7
8
# File 'lib/structured_event_logger.rb', line 6

def unstructured_logger
  @unstructured_logger
end

Instance Method Details

#contextObject



21
22
23
# File 'lib/structured_event_logger.rb', line 21

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

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



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

def event(scope, event, content = {})
  log_event({:scope => scope, :event => event}.merge(flatten_hash(content)))
end

#log(msg = nil) ⇒ Object



13
14
15
# File 'lib/structured_event_logger.rb', line 13

def log(msg = nil)
  unstructured_logger.add(nil, msg)
end