Class: Explorer::LogWatcher

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/explorer/log_watcher.rb

Defined Under Namespace

Classes: LogDevice

Constant Summary collapse

COLORS =
[:red, :green, :yellow, :blue, :magenta, :cyan]

Instance Method Summary collapse

Constructor Details

#initializeLogWatcher

Returns a new instance of LogWatcher.



8
9
10
11
# File 'lib/explorer/log_watcher.rb', line 8

def initialize
  @watchers = []
  @label_colors = {}
end

Instance Method Details

#add(watcher) ⇒ Object



13
14
15
# File 'lib/explorer/log_watcher.rb', line 13

def add(watcher)
  @watchers << watcher
end

#log(label, line) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# 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') ⇒ Object



33
34
35
# File 'lib/explorer/log_watcher.rb', line 33

def logger(label='system')
  @logger ||= ::Logger.new(LogDevice.new(self, label))
end

#remove(watcher) ⇒ Object



17
18
19
20
# File 'lib/explorer/log_watcher.rb', line 17

def remove(watcher)
  watcher.close unless watcher.closed?
  @watchers.delete watcher
end