Class: Timmy::Logger
- Inherits:
-
Object
- Object
- Timmy::Logger
- Defined in:
- lib/timmy/logger.rb
Class Method Summary collapse
- .clear ⇒ Object
- .finalize ⇒ Object
- .format_duration(duration) ⇒ Object
- .put(line, internal: false, since: 0) ⇒ Object
- .set_output_directory(dir) ⇒ Object
- .set_precision(precision) ⇒ Object
Class Method Details
.clear ⇒ Object
4 5 6 |
# File 'lib/timmy/logger.rb', line 4 def clear @output = '' end |
.finalize ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/timmy/logger.rb', line 27 def finalize suffix = "#{MasterTimer.start.to_i}+#{(MasterTimer.get).to_i}" filename = File.join(output_directory, "timmy-#{suffix}.log") put("EOF > #{filename}", internal: true) File.write(filename, @output) end |
.format_duration(duration) ⇒ Object
35 36 37 38 |
# File 'lib/timmy/logger.rb', line 35 def format_duration(duration) format = precision > 0 ? "%d:%0#{3 + precision}.#{precision}f" : "%d:%02d" sprintf(format, duration / 60, duration % 60) end |
.put(line, internal: false, since: 0) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/timmy/logger.rb', line 16 def put(line, internal: false, since: 0) duration = format_duration(MasterTimer.get - since) if internal @output += "#{duration} > #{line}\n" puts bold("#{duration} #{line}") else @output += "#{duration} | #{line}\n" puts feint(duration) + " " + line end end |
.set_output_directory(dir) ⇒ Object
8 9 10 |
# File 'lib/timmy/logger.rb', line 8 def set_output_directory(dir) @output_directory = dir end |
.set_precision(precision) ⇒ Object
12 13 14 |
# File 'lib/timmy/logger.rb', line 12 def set_precision(precision) @precision = precision end |