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.
-
#path ⇒ Object
readonly
protected
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
- #execute(command, status, output) ⇒ Object
- #execute_begin(command) ⇒ Object
- #execute_end(status, output) ⇒ Object
- #exit(status) ⇒ Object
-
#initialize(path) ⇒ MachineLog
constructor
A new instance of MachineLog.
- #kill(signal) ⇒ Object
- #log ⇒ Object protected
- #log_begin {|file| ... } ⇒ Object protected
- #log_cont {|file| ... } ⇒ Object protected
- #log_end(&block) ⇒ Object protected
Constructor Details
#initialize(path) ⇒ MachineLog
Returns a new instance of MachineLog.
3 4 5 6 |
# File 'lib/osvm/machine_log.rb', line 3 def initialize(path) @path = path @file = File.open(path, 'w') end |
Instance Attribute Details
#file ⇒ Object (readonly, protected)
Returns the value of attribute file.
55 56 57 |
# File 'lib/osvm/machine_log.rb', line 55 def file @file end |
#path ⇒ Object (readonly, protected)
Returns the value of attribute path.
55 56 57 |
# File 'lib/osvm/machine_log.rb', line 55 def path @path end |
Instance Method Details
#close ⇒ Object
49 50 51 |
# File 'lib/osvm/machine_log.rb', line 49 def close file.close end |
#execute(command, status, output) ⇒ Object
44 45 46 47 |
# File 'lib/osvm/machine_log.rb', line 44 def execute(command, status, output) execute_begin(command) execute_end(status, output) end |
#execute_begin(command) ⇒ Object
30 31 32 33 34 |
# File 'lib/osvm/machine_log.rb', line 30 def execute_begin(command) log_begin do |io| io.puts("COMMAND: #{command}") end end |
#execute_end(status, output) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/osvm/machine_log.rb', line 36 def execute_end(status, output) log_end do |io| io.puts("STATUS: #{status}") io.puts('OUTPUT:') io.puts(output) end end |
#exit(status) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/osvm/machine_log.rb', line 23 def exit(status) log do |io| io.puts('ACTION: qemu_exit') io.puts("STATUS: #{status}") end end |
#kill(signal) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/osvm/machine_log.rb', line 16 def kill(signal) log do |io| io.puts('ACTION: kill') io.puts("SIGNAL: #{signal}") end end |
#log ⇒ Object (protected)
57 58 59 60 61 |
# File 'lib/osvm/machine_log.rb', line 57 def log(&) log_begin log_cont(&) log_end end |
#log_begin {|file| ... } ⇒ Object (protected)
63 64 65 66 67 68 |
# File 'lib/osvm/machine_log.rb', line 63 def log_begin @log_begun_at = Time.now file.puts("START: #{@log_begun_at}") yield(file) if block_given? file.flush end |
#log_cont {|file| ... } ⇒ Object (protected)
70 71 72 73 |
# File 'lib/osvm/machine_log.rb', line 70 def log_cont yield(file) file.flush end |
#log_end(&block) ⇒ Object (protected)
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/osvm/machine_log.rb', line 75 def log_end(&block) t = Time.now file.puts("END: #{t}") file.puts("ELAPSED: #{(t - @log_begun_at).round(2)}s") file.flush log_cont(&block) if block file.puts('---') file.puts file.flush end |