Class: Logger

Inherits:
Object show all
Defined in:
lib/logger.rb

Overview

any output to console runs through this

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



11
12
13
# File 'lib/logger.rb', line 11

def initialize
  self.level = 5
end

Instance Attribute Details

#levelObject

higher level means more is logged. 0 means silent. 1 heading and %. 2 condensed stats and written files 3 warnings 4 memory updates and debug info 5 raw data



10
11
12
# File 'lib/logger.rb', line 10

def level
  @level
end

Instance Method Details

#log(str, lvl) ⇒ Object

output something if our level says it’s okay



16
17
18
19
20
21
# File 'lib/logger.rb', line 16

def log str, lvl
  raise "Don't write anything to log level 0." if lvl < 1
  extra = ""
  (lvl-1).times {extra+="_"}
  puts extra + str + extra if level >= lvl
end

puts without newline



34
35
36
37
# File 'lib/logger.rb', line 34

def print_and_flush(str)
  print str
  $stdout.flush
end

a loading bar



24
25
26
27
28
29
30
31
32
# File 'lib/logger.rb', line 24

def print_loading_bar(frames_index, len, percent_complete=nil, skipped_percent= 0, max= 100)
  percent = ((frames_index.to_f/len)*100).round(4)
  percent = percent.round if !percent_complete.nil?
  percent = skipped_percent + (percent.to_f/100.0)*(max-skipped_percent)
  if level > 0 && (percent_complete.nil? || (percent_complete.round < percent))  
    App.logger.print_and_flush(" #{percent.round}% ")
  end
  percent
end