Class: StructuredEventLogger

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

Constant Summary collapse

CLEAR =
"\e[0m"
BOLD =
"\e[1m"
MAGENTA =

Colors

"\e[35m"
CYAN =
"\e[36m"
WHITE =
"\e[37m"
VERSION =
"0.0.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_io, unstructured_logger = nil) ⇒ StructuredEventLogger

Returns a new instance of StructuredEventLogger.



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

def initialize(json_io, unstructured_logger = nil)
  @json_io, @unstructured_logger = json_io, unstructured_logger
  @thread_contexts = {}
  @default_context = {}
  @colorize_logging = ActiveSupport::LogSubscriber.colorize_logging
end

Instance Attribute Details

#colorize_loggingObject (readonly)

Returns the value of attribute colorize_logging.



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

def colorize_logging
  @colorize_logging
end

#default_contextObject (readonly)

Returns the value of attribute default_context.



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

def default_context
  @default_context
end

#json_ioObject (readonly)

Returns the value of attribute json_io.



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

def json_io
  @json_io
end

#unstructured_loggerObject (readonly)

Returns the value of attribute unstructured_logger.



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

def unstructured_logger
  @unstructured_logger
end

Instance Method Details

#contextObject



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

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

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



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

def event(scope, event, content = {})
  log_event scope, event, flatten_hash(content)
end

#log(msg = nil) ⇒ Object



23
24
25
# File 'lib/structured_event_logger.rb', line 23

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