class Explorer::LogWatcher

Constants

COLORS

Public Class Methods

new() click to toggle source
# File lib/explorer/log_watcher.rb, line 8
def initialize
  @watchers = []
  @label_colors = {}
end

Public Instance Methods

add(watcher) click to toggle source
# File lib/explorer/log_watcher.rb, line 13
def add(watcher)
  @watchers << watcher
end
log(label, line) click to toggle source
# File lib/explorer/log_watcher.rb, line 22
def log(label, line)
  @watchers.each do |watcher|
    begin
      color = @label_colors[label] ||= next_color
      watcher.puts Rainbow(label).color(color).bright + " : " + line
    rescue => e
      remove(watcher)
    end
  end
end
logger(label='system') click to toggle source
# File lib/explorer/log_watcher.rb, line 33
def logger(label='system')
  @logger ||= ::Logger.new(LogDevice.new(self, label))
end
remove(watcher) click to toggle source
# File lib/explorer/log_watcher.rb, line 17
def remove(watcher)
  watcher.close unless watcher.closed?
  @watchers.delete watcher
end

Private Instance Methods

next_color() click to toggle source
# File lib/explorer/log_watcher.rb, line 53
def next_color
  color = COLORS.shift
  COLORS.push color
  color
end