Class: StructuredEventLogger
- Inherits:
-
Object
- Object
- StructuredEventLogger
- 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
-
#default_context ⇒ Object
readonly
Returns the value of attribute default_context.
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
-
#error_handler ⇒ Object
Returns the value of attribute error_handler.
-
#only ⇒ Object
Returns the value of attribute only.
Instance Method Summary collapse
- #context ⇒ Object
- #event(scope, event, content = {}) ⇒ Object
-
#initialize(endpoints = {}) ⇒ StructuredEventLogger
constructor
A new instance of StructuredEventLogger.
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_context ⇒ Object (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 |
#endpoints ⇒ Object (readonly)
Returns the value of attribute endpoints.
15 16 17 |
# File 'lib/structured_event_logger.rb', line 15 def endpoints @endpoints end |
#error_handler ⇒ Object
Returns the value of attribute error_handler.
18 19 20 |
# File 'lib/structured_event_logger.rb', line 18 def error_handler @error_handler end |
#only ⇒ Object
Returns the value of attribute only.
17 18 19 |
# File 'lib/structured_event_logger.rb', line 17 def only @only end |
Instance Method Details
#context ⇒ Object
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 |