Module: TestLab::Utility::Logger
- Included in:
- TestLab::Utility
- Defined in:
- lib/testlab/utility/logger.rb
Overview
Logger Module
Instance Method Summary collapse
- #log_config(testlab) ⇒ Object
- #log_details(testlab) ⇒ Object
- #log_external_dependencies(testlab) ⇒ Object
- #log_gem_dependencies(testlab) ⇒ Object
- #log_header(testlab) ⇒ Object
- #log_key_value(key, value, max_key_length) ⇒ Object
- #log_page_break(max_key_length, char = '-') ⇒ Object
- #log_ruby(testlab) ⇒ Object
Instance Method Details
#log_config(testlab) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/testlab/utility/logger.rb', line 23 def log_config(testlab) { "config_dir" => testlab.config_dir.inspect, "repo_dir" => testlab.repo_dir.inspect, "labfile_path" => testlab.labfile_path.inspect, "logdev" => testlab.ui.logger.instance_variable_get(:@logdev).inspect, "version" => TestLab::VERSION.inspect, } end |
#log_details(testlab) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/testlab/utility/logger.rb', line 33 def log_details(testlab) @command ||= ZTK::Command.new(:silence => true, :ignore_exit_status => true) { "hostname" => "%s (%s)" % [Socket.gethostname.inspect, TestLab.hostname.inspect], "program" => $0.to_s.inspect, "argv" => ARGV.join(' ').inspect, "timezone" => Time.now.zone.inspect, "user" => ENV['USER'].inspect, "uname" => @command.exec(%(uname -a)).output.strip.inspect } end |
#log_external_dependencies(testlab) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/testlab/utility/logger.rb', line 72 def log_external_dependencies(testlab) @command ||= ZTK::Command.new(:silence => true, :ignore_exit_status => true) { "vagrant_version" => @command.exec(%(/usr/bin/env vagrant --version)).output.strip.inspect, "virtualbox_version" => @command.exec(%(/usr/bin/env vboxmanage --version)).output.strip.inspect, "lxc_version" => @command.exec(%(/usr/bin/env lxc-version)).output.strip.inspect } end |
#log_gem_dependencies(testlab) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/testlab/utility/logger.rb', line 60 def log_gem_dependencies(testlab) dependencies = { "lxc_version" => ::LXC::VERSION.inspect, "ztk_version" => ::ZTK::VERSION.inspect, "activesupport_version" => ::ActiveSupport::VERSION::STRING.inspect } defined?(::GLI) and dependencies.merge!("gli_version" => ::GLI::VERSION.inspect) dependencies end |
#log_header(testlab) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/testlab/utility/logger.rb', line 82 def log_header(testlab) log_lines = Array.new log_methods = [:log_details, :log_config, :log_ruby, :log_gem_dependencies, :log_external_dependencies] log_hashes = log_methods.collect{ |log_method| self.send(log_method, testlab) } max_key_length = log_hashes.collect{ |log_hash| log_hash.keys }.flatten.compact.map(&:length).max + 2 max_value_length = log_hashes.collect{ |log_hash| log_hash.values }.flatten.compact.map(&:length).max + 2 max_length = (max_key_length + max_value_length + 2) log_lines << log_page_break(max_length, '=') log_hashes.each do |log_hash| log_hash.sort.each do |key, value| log_lines << log_key_value(key, value, max_key_length) end log_lines << log_page_break(max_length, '=') end log_lines.flatten.compact end |
#log_key_value(key, value, max_key_length) ⇒ Object
14 15 16 |
# File 'lib/testlab/utility/logger.rb', line 14 def log_key_value(key, value, max_key_length) " %s%s: %s" % [ key.upcase, '.' * (max_key_length - key.length), value.to_s ] end |
#log_page_break(max_key_length, char = '-') ⇒ Object
18 19 20 21 |
# File 'lib/testlab/utility/logger.rb', line 18 def log_page_break(max_key_length, char='-') (max_key_length > 80) and (max_key_length = 80) (char * max_key_length) end |
#log_ruby(testlab) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/testlab/utility/logger.rb', line 46 def log_ruby(testlab) dependencies = { "ruby_version" => RUBY_VERSION.inspect, "ruby_patchlevel" => RUBY_PATCHLEVEL.inspect, "ruby_platform" => RUBY_PLATFORM.inspect } defined?(RUBY_ENGINE) and dependencies.merge!("ruby_engine" => RUBY_ENGINE.inspect) defined?(RUBY_DESCRIPTION) and dependencies.merge!("ruby_description" => RUBY_DESCRIPTION.inspect) defined?(RUBY_RELEASE_DATE) and dependencies.merge!("ruby_release_date" => RUBY_RELEASE_DATE.inspect) dependencies end |