Class: SemanticLogger::Appender::Splunk
- Defined in:
- lib/semantic_logger/appender/splunk.rb
Overview
Note: Not recommended to use the colorized formatter.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#service_index ⇒ Object
readonly
Returns the value of attribute service_index.
Attributes inherited from Base
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options, level = :error, &block) ⇒ Splunk
constructor
Allow the level for this appender to be overwritten Default: :error.
-
#log(log) ⇒ Object
Log the message to Splunk.
-
#reopen ⇒ Object
After forking an active process call #reopen to re-open open the handles to resources.
Methods inherited from Base
colorized_formatter, #default_formatter, #flush, #level
Methods inherited from Base
#benchmark, default_level, default_level=, #level, #level=, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload
Constructor Details
#initialize(options, level = :error, &block) ⇒ Splunk
Allow the level for this appender to be overwritten
Default: :error
9 10 11 12 13 14 15 16 17 |
# File 'lib/semantic_logger/appender/splunk.rb', line 9 def initialize(, level=:error, &block) # Parse input options for setting up splunk connection () reopen # Pass on the level and custom formatter if supplied super(level, &block) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/semantic_logger/appender/splunk.rb', line 5 def config @config end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
5 6 7 |
# File 'lib/semantic_logger/appender/splunk.rb', line 5 def index @index end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
5 6 7 |
# File 'lib/semantic_logger/appender/splunk.rb', line 5 def service @service end |
#service_index ⇒ Object (readonly)
Returns the value of attribute service_index.
5 6 7 |
# File 'lib/semantic_logger/appender/splunk.rb', line 5 def service_index @service_index end |
Instance Method Details
#log(log) ⇒ Object
Log the message to Splunk
30 31 32 33 34 35 36 |
# File 'lib/semantic_logger/appender/splunk.rb', line 30 def log(log) # Ensure minimum log level is met, and check filter return false if (level_index > (log.level_index || 0)) || !(log) # Submit the log message @service_index.submit(formatter.call(log)) true end |
#reopen ⇒ Object
After forking an active process call #reopen to re-open open the handles to resources
21 22 23 24 25 26 27 |
# File 'lib/semantic_logger/appender/splunk.rb', line 21 def reopen # Connect to splunk. Connect is a synonym for creating a Service by hand and calling login. @service = Splunk::connect(@config) # The index we are logging to @service_index = @service.indexes[@index] end |