module TestLab::Utility::Logger

Logger Module

@author Zachary Patten <zachary AT jovelabs DOT com>

Public Instance Methods

log_config(testlab) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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='-') click to toggle source
# 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) click to toggle source
# 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