Class: Oxidized::DebugText

Inherits:
Object
  • Object
show all
Includes:
SemanticLogger::Loggable
Defined in:
lib/oxidized/input/debugtext.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_debug, node, input_name) ⇒ DebugText

Returns a new instance of DebugText.



5
6
7
8
9
10
# File 'lib/oxidized/input/debugtext.rb', line 5

def initialize(config_debug, node, input_name)
  return unless config_debug == true ||
                (config_debug.is_a?(String) && config_debug.downcase.include?('text'))

  @log = File.open(logfile(node, input_name), 'w')
end

Instance Method Details

#closeObject



34
35
36
37
38
# File 'lib/oxidized/input/debugtext.rb', line 34

def close
  return unless @log

  @log.close
end

#logfile(node, input_name) ⇒ Object

Separate method to ease unit tests



13
14
15
16
17
18
# File 'lib/oxidized/input/debugtext.rb', line 13

def logfile(node, input_name)
  timestamp = Time.now.strftime('%Y%m%d-%H%M%S')
  file = Oxidized::Config::LOG + "/#{node&.ip}-#{input_name}-#{timestamp}.txt"
  logger.debug "Writing I/O Debugging to #{file}"
  file
end

#receive_data(data) ⇒ Object



27
28
29
30
31
32
# File 'lib/oxidized/input/debugtext.rb', line 27

def receive_data(data)
  return unless @log

  @log.puts "received #{data.dump}"
  @log.flush
end

#send_data(data) ⇒ Object



20
21
22
23
24
25
# File 'lib/oxidized/input/debugtext.rb', line 20

def send_data(data)
  return unless @log

  @log.puts "sent cmd #{data.dump}"
  @log.flush
end