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 written files. 2 condensed stats and updative info from a process (loading bars) 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



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

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

a loading bar



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

def print_loading_bar(frames_index, len, percent_complete=nil)
  percent = ((frames_index.to_f/len)*100).round(4)
  percent = percent.round if !percent_complete.nil?
  # puts "percent #{percent}"
  # puts "fun percent_complete #{percent_complete}"
  if level > 1 && (percent_complete.nil? || (percent_complete.round < percent))  
    App.logger.print_and_flush("__#{percent}%__")
  end
  percent
end