Class: SemanticLogger::Appender::Splunk

Inherits:
Base
  • Object
show all
Defined in:
lib/semantic_logger/appender/splunk.rb

Overview

Note: This appender is Deprecated. Use: SemanticLogger::Appender::SplunkHttp

Instance Attribute Summary collapse

Attributes inherited from Base

#formatter

Attributes inherited from Base

#filter, #name

Instance Method Summary collapse

Methods inherited from Base

colorized_formatter, #default_formatter, #flush, json_formatter, #level

Methods inherited from Base

#benchmark, default_level, default_level=, #fast_tag, #level, #level=, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload

Constructor Details

#initialize(options, level = :error, &block) ⇒ Splunk

DEPRECATED, Please use SemanticLogger::Appender::SplunkHttp



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/semantic_logger/appender/splunk.rb', line 12

def initialize(options, level=:error, &block)
  Kernel.warn('Splunk Appender is deprecated, please use SemanticLogger::Appender::SplunkHttp')

  # Parse input options for setting up splunk connection
  parse_options(options)

  reopen

  # Pass on the level and custom formatter if supplied
  super(level, &block)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/semantic_logger/appender/splunk.rb', line 9

def config
  @config
end

#indexObject (readonly)

Returns the value of attribute index.



9
10
11
# File 'lib/semantic_logger/appender/splunk.rb', line 9

def index
  @index
end

#serviceObject (readonly)

Returns the value of attribute service.



9
10
11
# File 'lib/semantic_logger/appender/splunk.rb', line 9

def service
  @service
end

#service_indexObject (readonly)

Returns the value of attribute service_index.



9
10
11
# File 'lib/semantic_logger/appender/splunk.rb', line 9

def service_index
  @service_index
end

Instance Method Details

#log(log) ⇒ Object

Log the message to Splunk



35
36
37
38
39
40
41
# File 'lib/semantic_logger/appender/splunk.rb', line 35

def log(log)
  # Ensure minimum log level is met, and check filter
  return false if (level_index > (log.level_index || 0)) || !include_message?(log)
  # Submit the log message
  @service_index.submit(formatter.call(log, self))
  true
end

#reopenObject

After forking an active process call #reopen to re-open open the handles to resources



26
27
28
29
30
31
32
# File 'lib/semantic_logger/appender/splunk.rb', line 26

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