Class: Omnizip::Progress::LogReporter
- Inherits:
-
ProgressReporter
- Object
- ProgressReporter
- Omnizip::Progress::LogReporter
- Defined in:
- lib/omnizip/progress/log_reporter.rb
Overview
Progress reporter that writes to a log file.
This reporter writes timestamped progress updates to a log file, useful for debugging, auditing, or monitoring long-running operations.
Instance Attribute Summary collapse
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#finish(progress) ⇒ Object
Called when operation completes.
-
#initialize(log_file:, verbose: false) ⇒ LogReporter
constructor
Initialize a new log reporter.
-
#report(progress) ⇒ Object
Report progress to log file.
-
#start(progress) ⇒ Object
Called when operation starts.
Constructor Details
#initialize(log_file:, verbose: false) ⇒ LogReporter
Initialize a new log reporter
20 21 22 23 24 25 |
# File 'lib/omnizip/progress/log_reporter.rb', line 20 def initialize(log_file:, verbose: false) super() @log_file = log_file.is_a?(String) ? File.open(log_file, "a") : log_file @verbose = verbose @owns_file = log_file.is_a?(String) end |
Instance Attribute Details
#log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
14 15 16 |
# File 'lib/omnizip/progress/log_reporter.rb', line 14 def log_file @log_file end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
14 15 16 |
# File 'lib/omnizip/progress/log_reporter.rb', line 14 def verbose @verbose end |
Instance Method Details
#finish(progress) ⇒ Object
Called when operation completes
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/omnizip/progress/log_reporter.rb', line 75 def finish(progress) = Time.now.strftime("%Y-%m-%d %H:%M:%S") log_file.puts format( "[%s] Completed in %.2fs", , progress.elapsed_seconds, ) log_file.flush # Close file if we opened it log_file.close if @owns_file end |
#report(progress) ⇒ Object
Report progress to log file
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/omnizip/progress/log_reporter.rb', line 30 def report(progress) = Time.now.strftime("%Y-%m-%d %H:%M:%S") if verbose log_file.puts format( "[%s] Progress: %.1f%% (%d/%d files, %d/%d bytes) - %s - %s - ETA: %s", , progress.percentage, progress.files_processed, progress.operation_progress.total_files, progress.bytes_processed, progress.operation_progress.total_bytes, progress.current_file || "unknown", progress.rate_formatted, progress.eta_formatted, ) else log_file.puts format( "[%s] Progress: %.1f%% - %s", , progress.percentage, progress.current_file || "processing", ) end log_file.flush end |
#start(progress) ⇒ Object
Called when operation starts
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/omnizip/progress/log_reporter.rb', line 61 def start(progress) = Time.now.strftime("%Y-%m-%d %H:%M:%S") log_file.puts format( "[%s] Started: %d files, %d bytes", , progress.operation_progress.total_files, progress.operation_progress.total_bytes, ) log_file.flush end |