Class: OsVm::MachineLog

Inherits:
Object
  • Object
show all
Defined in:
lib/osvm/machine_log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fileObject (readonly, protected)

Returns the value of attribute file.



69
70
71
# File 'lib/osvm/machine_log.rb', line 69

def file
  @file
end

#pathObject (readonly, protected)

Returns the value of attribute path.



69
70
71
# File 'lib/osvm/machine_log.rb', line 69

def path
  @path
end

Instance Method Details

#closeObject



63
64
65
# File 'lib/osvm/machine_log.rb', line 63

def close
  file.close
end

#console_wait_begin(regex) ⇒ Object



49
50
51
52
53
54
# File 'lib/osvm/machine_log.rb', line 49

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) ⇒ Object



56
57
58
59
60
61
# File 'lib/osvm/machine_log.rb', line 56

def console_wait_end(status, error = nil)
  log_end do |io|
    io.puts("MATCH: #{status}")
    io.puts("ERROR: #{error}") if error
  end
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

#logObject (protected)



71
72
73
74
75
# File 'lib/osvm/machine_log.rb', line 71

def log(&)
  log_begin
  log_cont(&)
  log_end
end

#log_begin {|file| ... } ⇒ Object (protected)

Yields:



77
78
79
80
81
82
# File 'lib/osvm/machine_log.rb', line 77

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)

Yields:



84
85
86
87
# File 'lib/osvm/machine_log.rb', line 84

def log_cont
  yield(file)
  file.flush
end

#log_end(&block) ⇒ Object (protected)



89
90
91
92
93
94
95
96
97
98
# File 'lib/osvm/machine_log.rb', line 89

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