Class: EventHub::Components::StructuredDataLogger
- Inherits:
-
Object
- Object
- EventHub::Components::StructuredDataLogger
- Defined in:
- lib/eventhub/components/structured_data_logger.rb
Overview
All methods besides debug/info/warn/error/fatal are forwarded to the target by the means of method_missing.
Constant Summary collapse
- SEVERITY_DEBUG =
7- SEVERITY_INFO =
6- SEVERITY_WARNING =
4- SEVERITY_ERROR =
3- SEVERITY_FATAL =
0
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #debug(message, structured_data = nil) ⇒ Object
- #error(message, structured_data = nil) ⇒ Object
-
#fatal(message, structured_data = nil) ⇒ Object
fatal <=> emergeny <=> alert.
- #info(message, structured_data = nil) ⇒ Object
-
#initialize(target, options) ⇒ StructuredDataLogger
constructor
Create a new Logger target: an onject which behaves like a ruby logger.
- #warn(message, structured_data = nil) ⇒ Object
Constructor Details
#initialize(target, options) ⇒ StructuredDataLogger
Create a new Logger target: an onject which behaves like a ruby logger. options (keys are Strings):
-
app_name: String, mandatory
-
env: String, mandatory
-
pid: Number, optional, defaults to Process.pid
-
hostname, String, optional, defaults to Socket.gethostname
additional keys are possible and will be sent along. The keys :data and :message are reserved and must not be used.
21 22 23 24 25 26 27 |
# File 'lib/eventhub/components/structured_data_logger.rb', line 21 def initialize(target, ) @target = target @options = @options["pid"] ||= ::Process.pid @options["hostname"] ||= ::Socket.gethostname end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object (private)
52 53 54 |
# File 'lib/eventhub/components/structured_data_logger.rb', line 52 def method_missing(...) target.send(...) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/eventhub/components/structured_data_logger.rb', line 11 def @options end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
11 12 13 |
# File 'lib/eventhub/components/structured_data_logger.rb', line 11 def target @target end |
Instance Method Details
#debug(message, structured_data = nil) ⇒ Object
29 30 31 |
# File 'lib/eventhub/components/structured_data_logger.rb', line 29 def debug(, structured_data = nil) target.debug((SEVERITY_DEBUG, , structured_data)) end |
#error(message, structured_data = nil) ⇒ Object
41 42 43 |
# File 'lib/eventhub/components/structured_data_logger.rb', line 41 def error(, structured_data = nil) target.error((SEVERITY_ERROR, , structured_data)) end |
#fatal(message, structured_data = nil) ⇒ Object
fatal <=> emergeny <=> alert
46 47 48 |
# File 'lib/eventhub/components/structured_data_logger.rb', line 46 def fatal(, structured_data = nil) target.fatal((SEVERITY_FATAL, , structured_data)) end |
#info(message, structured_data = nil) ⇒ Object
33 34 35 |
# File 'lib/eventhub/components/structured_data_logger.rb', line 33 def info(, structured_data = nil) target.info((SEVERITY_INFO, , structured_data)) end |
#warn(message, structured_data = nil) ⇒ Object
37 38 39 |
# File 'lib/eventhub/components/structured_data_logger.rb', line 37 def warn(, structured_data = nil) target.warn((SEVERITY_WARNING, , structured_data)) end |