Module: Oschii::Logging

Included in:
Device
Defined in:
lib/oschii/logging.rb

Instance Method Summary collapse

Instance Method Details

#logger(params = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/oschii/logging.rb', line 14

def logger(params = {})
  current_logger = settings['logger']

  all = params[:all]

  sensors = all.nil? ? params[:sensors] : all
  drivers = all.nil? ? params[:drivers] : all
  monitors = all.nil? ? params[:monitors] : all
  listeners = all.nil? ? params[:listeners] : all
  states = all.nil? ? params[:states] : all
  timers = all.nil? ? params[:timers] : all
  subs = all.nil? ? params[:subs] : all
  pixels = all.nil? ? params[:pixels] : all
  network_in = all.nil? ? params[:network_in] : all
  network_out = all.nil? ? params[:network_out] : all
  timestamp = params[:timestamp]
  to_file = params[:to_file]

  current_logger['sensors'] = sensors unless sensors.nil?
  current_logger['drivers'] = drivers unless drivers.nil?
  current_logger['monitors'] = monitors unless monitors.nil?
  current_logger['listeners'] = listeners unless listeners.nil?
  current_logger['states'] = states unless states.nil?
  current_logger['timers'] = timers unless timers.nil?
  current_logger['subs'] = subs unless subs.nil?
  current_logger['pixels'] = pixels unless pixels.nil?
  current_logger['networkIn'] = network_in unless network_in.nil?
  current_logger['networkOut'] = network_out unless network_out.nil?
  current_logger['timestamp'] = timestamp unless timestamp.nil?
  current_logger['logToFile'] = to_file unless to_file.nil?
  update_settings({ 'logger' => current_logger })
  current_logger = settings['logger']
  puts JSON.pretty_generate current_logger
end

#tail(filter: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/oschii/logging.rb', line 3

def tail(filter: nil)
  while true
    while (line = log_lines.shift)
      if filter.nil? || line.match?(filter)
        puts line
      end
    end
    sleep 0.05
  end
end