Class: Logger
Overview
any output to console runs through this
Instance Attribute Summary collapse
-
#level ⇒ Object
higher level means more is logged.
Instance Method Summary collapse
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
-
#log(str, lvl) ⇒ Object
output something if our level says it’s okay.
-
#print_and_flush(str) ⇒ Object
puts without newline.
-
#print_loading_bar(frames_index, len, percent_complete = nil, skipped_percent = 0, max = 100) ⇒ Object
a loading bar.
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
11 12 13 |
# File 'lib/logger.rb', line 11 def initialize self.level = 5 end |
Instance Attribute Details
#level ⇒ Object
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 |
#print_and_flush(str) ⇒ Object
puts without newline
34 35 36 37 |
# File 'lib/logger.rb', line 34 def print_and_flush(str) print str $stdout.flush end |
#print_loading_bar(frames_index, len, percent_complete = nil, skipped_percent = 0, max = 100) ⇒ Object
a loading bar
24 25 26 27 28 29 30 31 32 |
# File 'lib/logger.rb', line 24 def (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 |