Module: Roby::Test::DRobyLogHelpers
- Defined in:
- lib/roby/test/droby_log_helpers.rb
Overview
Helpers to create droby log files for log-related tests
Instance Method Summary collapse
-
#droby_close_event_log ⇒ Object
Close the last event log (and file) created by #droby_create_event_log.
-
#droby_create_event_log(path) ⇒ Object
Create an event log file.
-
#droby_current_event_logger ⇒ Object
The event logger last created by #droby_create_event_log.
-
#droby_event_log_path ⇒ Object
Path to the last log file created by #droby_create_event_log.
-
#droby_flush_cycle ⇒ Object
Finish the current cycle’s log and flush it to file.
-
#droby_write_event(method_name, *args, time: Time.now) ⇒ Object
Add an event to the current event cycle.
Instance Method Details
#droby_close_event_log ⇒ Object
Close the last event log (and file) created by #droby_create_event_log
71 72 73 74 75 |
# File 'lib/roby/test/droby_log_helpers.rb', line 71 def droby_close_event_log droby_flush_cycle @__event_logger.close @__event_logger = nil end |
#droby_create_event_log(path) ⇒ DRoby::EventLogger #droby_create_event_log(path) {|| ... } ⇒ String
Create an event log file
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/roby/test/droby_log_helpers.rb', line 28 def droby_create_event_log(path) unless path.start_with?("/") dir = make_tmpdir path = File.join(dir, path) end @__event_log_path = path io = File.open(path, "w") logfile = DRoby::Logfile::Writer.new(io) @__event_logger = DRoby::EventLogger.new(logfile) @__cycle_start = Time.now @__cycle_index = 0 return @__event_logger unless block_given? begin yield path ensure droby_close_event_log end end |
#droby_current_event_logger ⇒ Object
The event logger last created by #droby_create_event_log
This is reset with #droby_close_event_log
59 60 61 |
# File 'lib/roby/test/droby_log_helpers.rb', line 59 def droby_current_event_logger @__event_logger end |
#droby_event_log_path ⇒ Object
Path to the last log file created by #droby_create_event_log
This is reset with #droby_close_event_log
66 67 68 |
# File 'lib/roby/test/droby_log_helpers.rb', line 66 def droby_event_log_path @__event_log_path end |
#droby_flush_cycle ⇒ Object
Finish the current cycle’s log and flush it to file
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/roby/test/droby_log_helpers.rb', line 78 def droby_flush_cycle t = Time.now @__event_logger.flush_cycle( :cycle_end, t, [{ start: [@__cycle_start.tv_sec, @__cycle_start.tv_usec], end: (t - @__cycle_start), cycle_index: (@__cycle_index += 1) }] ) @__cycle_start = t end |
#droby_write_event(method_name, *args, time: Time.now) ⇒ Object
Add an event to the current event cycle
52 53 54 |
# File 'lib/roby/test/droby_log_helpers.rb', line 52 def droby_write_event(method_name, *args, time: Time.now) @__event_logger.dump(method_name, time, args) end |