Class: HybridPlatformsConductor::LoggerHelpers::ProgressBarLogDevice
- Inherits:
-
Object
- Object
- HybridPlatformsConductor::LoggerHelpers::ProgressBarLogDevice
- Defined in:
- lib/hybrid_platforms_conductor/logger_helpers.rb
Overview
Small custom log device that can use a progress bar currently in use.
Instance Method Summary collapse
-
#close ⇒ Object
Close the log device This method is needed for Ruby loggers to detect this class as a log device.
-
#flush ⇒ Object
Make sure if the current line is not flushed we still do it.
-
#initialize(progress_bar, stream) ⇒ ProgressBarLogDevice
constructor
Constructor.
-
#write(msg) ⇒ Object
Write a message.
Constructor Details
#initialize(progress_bar, stream) ⇒ ProgressBarLogDevice
Constructor
- Parameters
-
progress_bar (ProgressBar): The progress bar to be used for logging
-
stream (IO): Stream to be used for logging (like $stdoutā¦)
19 20 21 22 23 24 |
# File 'lib/hybrid_platforms_conductor/logger_helpers.rb', line 19 def initialize(, stream) @progress_bar = @stream = stream # Store the current line in case it wasn't finished by \n @current_line = nil end |
Instance Method Details
#close ⇒ Object
Close the log device This method is needed for Ruby loggers to detect this class as a log device.
53 54 |
# File 'lib/hybrid_platforms_conductor/logger_helpers.rb', line 53 def close end |
#flush ⇒ Object
Make sure if the current line is not flushed we still do it
57 58 59 60 61 62 |
# File 'lib/hybrid_platforms_conductor/logger_helpers.rb', line 57 def flush unless @current_line.nil? @stream << @current_line @current_line = nil end end |
#write(msg) ⇒ Object
Write a message
- Parameters
-
msg (String): Message to log
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hybrid_platforms_conductor/logger_helpers.rb', line 30 def write(msg) if msg.end_with?("\n") @progress_bar.clear if @current_line.nil? # New messages to be displayed @stream << msg else # Ending previous line @stream << (@current_line + msg) @current_line = nil end @progress_bar.refresh(force: true) unless @progress_bar.stopped? elsif @current_line.nil? # Beginning new line @current_line = msg else # Continuing current line @current_line << msg end end |