Class: OsVm::MachineLog
- Inherits:
-
Object
- Object
- OsVm::MachineLog
- Defined in:
- lib/osvm/machine_log.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
protected
Returns the value of attribute file.
-
#mutex ⇒ Object
readonly
protected
Returns the value of attribute mutex.
-
#path ⇒ Object
readonly
protected
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
- #console_wait_begin(regex) ⇒ Object
- #console_wait_end(status, error = nil, begun_at = nil) ⇒ Object
- #exit(status) ⇒ Object
-
#initialize(path) ⇒ MachineLog
constructor
A new instance of MachineLog.
- #kill(signal) ⇒ Object
- #log ⇒ Object protected
- #log_begin ⇒ Object protected
- #log_cont ⇒ Object protected
- #log_end(begun_at = nil, &block) ⇒ Object protected
Constructor Details
#initialize(path) ⇒ MachineLog
Returns a new instance of MachineLog.
3 4 5 6 7 |
# File 'lib/osvm/machine_log.rb', line 3 def initialize(path) @path = path @file = File.open(path, 'w') @mutex = Mutex.new end |
Instance Attribute Details
#file ⇒ Object (readonly, protected)
Returns the value of attribute file.
51 52 53 |
# File 'lib/osvm/machine_log.rb', line 51 def file @file end |
#mutex ⇒ Object (readonly, protected)
Returns the value of attribute mutex.
51 52 53 |
# File 'lib/osvm/machine_log.rb', line 51 def mutex @mutex end |
#path ⇒ Object (readonly, protected)
Returns the value of attribute path.
51 52 53 |
# File 'lib/osvm/machine_log.rb', line 51 def path @path end |
Instance Method Details
#close ⇒ Object
45 46 47 |
# File 'lib/osvm/machine_log.rb', line 45 def close file.close end |
#console_wait_begin(regex) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/osvm/machine_log.rb', line 31 def console_wait_begin(regex) log_begin do |io| io.puts('ACTION: console-wait') io.puts("REGEXP: #{regex.inspect}") end end |
#console_wait_end(status, error = nil, begun_at = nil) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/osvm/machine_log.rb', line 38 def console_wait_end(status, error = nil, begun_at = nil) log_end(begun_at) do |io| io.puts("MATCH: #{status}") io.puts("ERROR: #{error}") if error end end |
#exit(status) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/osvm/machine_log.rb', line 24 def exit(status) log do |io| io.puts('ACTION: qemu_exit') io.puts("STATUS: #{status}") end end |
#kill(signal) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/osvm/machine_log.rb', line 17 def kill(signal) log do |io| io.puts('ACTION: kill') io.puts("SIGNAL: #{signal}") end end |
#log ⇒ Object (protected)
53 54 55 56 57 |
# File 'lib/osvm/machine_log.rb', line 53 def log(&) begun_at = log_begin log_cont(&) log_end(begun_at) end |
#log_begin ⇒ Object (protected)
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/osvm/machine_log.rb', line 59 def log_begin begun_at = Time.now mutex.synchronize do file.puts("START: #{begun_at}") yield(file) if block_given? file.flush end begun_at end |
#log_cont ⇒ Object (protected)
71 72 73 74 75 76 |
# File 'lib/osvm/machine_log.rb', line 71 def log_cont mutex.synchronize do yield(file) file.flush end end |
#log_end(begun_at = nil, &block) ⇒ Object (protected)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/osvm/machine_log.rb', line 78 def log_end(begun_at = nil, &block) t = Time.now started_at = begun_at || t mutex.synchronize do file.puts("END: #{t}") file.puts("ELAPSED: #{(t - started_at).round(2)}s") if block yield(file) file.flush end file.puts('---') file.puts file.flush end end |