Class: LogMagic

Inherits:
Object
  • Object
show all
Defined in:
lib/log_magic.rb,
lib/log_magic/utils/port_utils.rb

Defined Under Namespace

Modules: JSONUtils, PortUtils, TemplatingUtils Classes: BaseExplainer, BaseRefiner, HoverRenderer, LogListener, MySqlExplainer, MySqlPrinter, MySqlRefiner, PersistanceLayer, SearchkickExplainer, SearchkickPrinter, SearchkickRefiner

Instance Method Summary collapse

Constructor Details

#initialize(log_file_name) ⇒ LogMagic

Returns a new instance of LogMagic.



4
5
6
7
# File 'lib/log_magic.rb', line 4

def initialize(log_file_name)
  @log_file_name = log_file_name
  reset_refiners
end

Instance Method Details

#add_line_to_refiners(line) ⇒ Object



23
24
25
26
27
# File 'lib/log_magic.rb', line 23

def add_line_to_refiners(line)
  @refiners.each do |refiner|
    refiner.lines << line
  end
end

#add_mysql_refinerObject



41
42
43
# File 'lib/log_magic.rb', line 41

def add_mysql_refiner
  @refiners << MySqlRefiner.new
end

#add_searchkick_refinerObject



37
38
39
# File 'lib/log_magic.rb', line 37

def add_searchkick_refiner
  @refiners << SearchkickRefiner.new
end

#check_for_refiner_matchObject



29
30
31
32
33
34
35
# File 'lib/log_magic.rb', line 29

def check_for_refiner_match
  @refiners.any? do |refiner|
    if refiner.matches?
      yield refiner
    end
  end
end

#initialize_listenerObject



9
10
11
# File 'lib/log_magic.rb', line 9

def initialize_listener
  @log_listener = LogListener.new(@log_file_name)
end

#reset_refinersObject



45
46
47
48
49
# File 'lib/log_magic.rb', line 45

def reset_refiners
  @refiners = []
  add_searchkick_refiner
  add_mysql_refiner
end

#startObject



13
14
15
16
17
18
19
20
21
# File 'lib/log_magic.rb', line 13

def start
  @log_listener.listen do |line|
    add_line_to_refiners(line)
    check_for_refiner_match do |refiner|
      puts refiner.compute
    end
    reset_refiners
  end
end