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.
57 58 59 |
# File 'lib/osvm/machine_log.rb', line 57 def file @file end |
#mutex ⇒ Object (readonly, protected)
Returns the value of attribute mutex.
57 58 59 |
# File 'lib/osvm/machine_log.rb', line 57 def mutex @mutex end |
#path ⇒ Object (readonly, protected)
Returns the value of attribute path.
57 58 59 |
# File 'lib/osvm/machine_log.rb', line 57 def path @path end |
Instance Method Details
#close ⇒ Object
51 52 53 |
# File 'lib/osvm/machine_log.rb', line 51 def close file.close end |
#console_wait_begin(regex) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/osvm/machine_log.rb', line 37 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
44 45 46 47 48 49 |
# File 'lib/osvm/machine_log.rb', line 44 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 30 31 32 33 34 35 |
# File 'lib/osvm/machine_log.rb', line 24 def exit(status) log do |io| io.puts('ACTION: qemu_exit') io.puts("STATUS: #{status.exitstatus}") if status.signaled? io.puts("TERMSIG: #{status.termsig}") io.puts("TERMSIG_NAME: SIG#{Signal.signame(status.termsig)}") io.puts("COREDUMP: #{status.coredump?}") end 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)
59 60 61 62 63 |
# File 'lib/osvm/machine_log.rb', line 59 def log(&) begun_at = log_begin log_cont(&) log_end(begun_at) end |
#log_begin ⇒ Object (protected)
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/osvm/machine_log.rb', line 65 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)
77 78 79 80 81 82 |
# File 'lib/osvm/machine_log.rb', line 77 def log_cont mutex.synchronize do yield(file) file.flush end end |
#log_end(begun_at = nil, &block) ⇒ Object (protected)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/osvm/machine_log.rb', line 84 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 |