Class: RubyJobs::Logging::ProgressLogger
- Inherits:
-
PlainLogger
- Object
- PlainLogger
- RubyJobs::Logging::ProgressLogger
- Defined in:
- lib/logging/progress_logger.rb
Constant Summary collapse
- PATH =
"log/progress"
Constants inherited from PlainLogger
RubyJobs::Logging::PlainLogger::DEFAULT_PATH
Instance Attribute Summary collapse
-
#end ⇒ Object
Returns the value of attribute end.
-
#progress ⇒ Object
Returns the value of attribute progress.
-
#progress_key ⇒ Object
Returns the value of attribute progress_key.
-
#start ⇒ Object
Returns the value of attribute start.
Attributes inherited from PlainLogger
#extension, #path, #print_timestamp, #separator, #time_prefix
Instance Method Summary collapse
-
#initialize(*names) ⇒ ProgressLogger
constructor
A new instance of ProgressLogger.
- #log(progress, *message) {|@progress, message| ... } ⇒ Object
Methods inherited from PlainLogger
#def_puts, #exist?, #file, #file_name, #file_path, #log_dir, #puts, #timestamp
Constructor Details
#initialize(*names) ⇒ ProgressLogger
Returns a new instance of ProgressLogger.
6 7 8 9 10 11 12 13 14 |
# File 'lib/logging/progress_logger.rb', line 6 def initialize(*names) super @path = PATH @start = 0.0 @end = 100.0 @progress = 0.0 @progress_key = :count = true end |
Instance Attribute Details
#end ⇒ Object
Returns the value of attribute end.
17 18 19 |
# File 'lib/logging/progress_logger.rb', line 17 def end @end end |
#progress ⇒ Object
Returns the value of attribute progress.
16 17 18 |
# File 'lib/logging/progress_logger.rb', line 16 def progress @progress end |
#progress_key ⇒ Object
Returns the value of attribute progress_key.
16 17 18 |
# File 'lib/logging/progress_logger.rb', line 16 def progress_key @progress_key end |
#start ⇒ Object
Returns the value of attribute start.
17 18 19 |
# File 'lib/logging/progress_logger.rb', line 17 def start @start end |
Instance Method Details
#log(progress, *message) {|@progress, message| ... } ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/logging/progress_logger.rb', line 27 def log(progress, *) if progress.is_a?(Hash) && progress.include?(@progress_key) @progress = (progress[@progress_key].to_f - @start) / (@end - @start) * 100.0 = ([progress] + ) elsif !progress.is_a?(String) && progress.respond_to?(:to_f) @progress = (progress.to_f - @start) / (@end - @start) * 100.0 = [progress] if .empty? else = ([progress] + ) end if = false messsage = super @progress.to_i, "%", , "-", * = true else messsage = super @progress.to_i, "%", * end yield @progress, if block_given? messsage end |