Class: CrashLog::SystemInformation

Inherits:
Object
  • Object
show all
Defined in:
lib/crash_log/system_information.rb

Class Method Summary collapse

Class Method Details

.application_rootObject



71
72
73
# File 'lib/crash_log/system_information.rb', line 71

def application_root
  CrashLog.configuration.root
end

.environmentObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/crash_log/system_information.rb', line 35

def environment
  if ENV.respond_to?(:to_hash)
    env = ENV.to_hash.reject do |k, v|
      (k =~ /^HTTP_/)
    end

    unless CrashLog.configuration.environment_filters.empty?
      env.each do |k, v|
        if CrashLog.configuration.environment_filters.any? { |f|
            f.is_a?(Regexp) ? f =~ k.to_s : f.to_s == k.to_s
          }
          env[k] = '[FILTERED]'
        end
      end
    end

    env
  else
    {}
  end
rescue
  {}
end

.hostnameObject



18
19
20
21
22
23
# File 'lib/crash_log/system_information.rb', line 18

def hostname
  require 'socket' unless defined?(Socket)
  Socket.gethostname
rescue
  'UNKNOWN'
end

.libraries_loadedObject



59
60
61
62
63
64
65
# File 'lib/crash_log/system_information.rb', line 59

def libraries_loaded
  Hash[*Gem.loaded_specs.map {|name, gem_specification|
    [name, gem_specification.version.to_s]
  }.flatten]
rescue
  {}
end

.platformObject



67
68
69
# File 'lib/crash_log/system_information.rb', line 67

def platform
  RUBY_PLATFORM rescue '????'
end

.ruby_versionObject



25
26
27
# File 'lib/crash_log/system_information.rb', line 25

def ruby_version
  "#{RUBY_VERSION rescue '?.?.?'}-p#{RUBY_PATCHLEVEL rescue '???'} #{RUBY_RELEASE_DATE rescue '????-??-??'} #{RUBY_PLATFORM rescue '????'}"
end

.stageObject



75
76
77
# File 'lib/crash_log/system_information.rb', line 75

def stage
  CrashLog.configuration.stage
end

.to_hashObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/crash_log/system_information.rb', line 5

def to_hash
  {
    :hostname => hostname,
    :ruby_version => ruby_version,
    :username => username,
    :environment => environment,
    :libraries_loaded => libraries_loaded,
    :platform => platform,
    :application_root => application_root,
    :stage => stage
  }
end

.usernameObject



29
30
31
32
33
# File 'lib/crash_log/system_information.rb', line 29

def username
  ENV['LOGNAME'] || ENV['USER'] || ENV['USERNAME'] || ENV['APACHE_RUN_USER'] || 'UNKNOWN'
rescue
  nil
end