Module: LogStash::Environment

Extended by:
Environment
Included in:
Environment
Defined in:
lib/logstash/environment.rb,
lib/logstash/environment.rb

Constant Summary collapse

LOGSTASH_HOME =
Stud::Temporary.directory("logstash-home")
LOGSTASH_CORE =
::File.expand_path(::File.join(::File.dirname(__FILE__), "..", ".."))
LOGSTASH_ENV =
(ENV["LS_ENV"] || 'production').to_s.freeze
LINUX_OS_RE =
/linux/
WINDOW_OS_RE =
/mswin|msys|mingw|cygwin|bccwin|wince|emc/
MACOS_OS_RE =
/darwin/

Instance Method Summary collapse

Instance Method Details

#add_plugin_path(path) ⇒ Object

add path for bare/ungemified plugins lookups. the path must be the base path that will include the dir structure ‘logstash/TYPE/NAME.rb’ where TYPE is ‘inputs’ ‘filters’, ‘outputs’ or ‘codecs’ and NAME is the name of the plugin

Parameters:

  • path (String)

    plugins path to add



188
189
190
# File 'lib/logstash/environment.rb', line 188

def add_plugin_path(path)
  $LOAD_PATH << path
end

#development?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/logstash/environment.rb', line 117

def development?
  env.downcase == "development"
end

#envObject



109
110
111
# File 'lib/logstash/environment.rb', line 109

def env
  LOGSTASH_ENV
end

#find_jars(pattern) ⇒ Object



146
147
148
149
150
151
# File 'lib/logstash/environment.rb', line 146

def find_jars(pattern)
  require 'java'
  jar_files = Dir.glob(pattern)
  raise(LogStash::EnvironmentError, I18n.t("logstash.environment.missing-jars", :pattern => pattern)) if jar_files.empty?
  jar_files
end

#linux?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/logstash/environment.rb', line 168

def linux?
  RbConfig::CONFIG['host_os'] =~ LINUX_OS_RE
end

#load_jars!(pattern) ⇒ Object



141
142
143
144
# File 'lib/logstash/environment.rb', line 141

def load_jars!(pattern)
  jar_files = find_jars(pattern)
  require_jars! jar_files
end

#load_locale!Object



176
177
178
179
180
181
182
# File 'lib/logstash/environment.rb', line 176

def load_locale!
  require "i18n"
  I18n.enforce_available_locales = true
  I18n.load_path << LogStash::Environment.locales_path("en.yml")
  I18n.reload!
  fail "No locale? This is a bug." if I18n.available_locales.empty?
end

#load_runtime_jars!(dir_name = "vendor", package = "jar-dependencies") ⇒ Object



133
134
135
# File 'lib/logstash/environment.rb', line 133

def load_runtime_jars!(dir_name="vendor", package="jar-dependencies")
  load_jars!(::File.join(runtime_jars_root(dir_name, package), "*.jar"))
end

#load_test_jars!(dir_name = "vendor", package = "jar-dependencies") ⇒ Object



137
138
139
# File 'lib/logstash/environment.rb', line 137

def load_test_jars!(dir_name="vendor", package="jar-dependencies")
  load_jars!(::File.join(test_jars_root(dir_name, package), "*.jar"))
end

#locales_path(path) ⇒ Object



172
173
174
# File 'lib/logstash/environment.rb', line 172

def locales_path(path)
  return ::File.join(LOGSTASH_CORE, "locales", path)
end

#production?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/logstash/environment.rb', line 113

def production?
  env.downcase == "production"
end

#require_jars!(files) ⇒ Object



153
154
155
156
157
158
# File 'lib/logstash/environment.rb', line 153

def require_jars!(files)
  files.each do |jar_file|
    loaded = require jar_file
    puts("Loaded #{jar_file}") if $DEBUG && loaded
  end
end

#ruby_binObject



160
161
162
# File 'lib/logstash/environment.rb', line 160

def ruby_bin
  ENV["USE_RUBY"] == "1" ? "ruby" : File.join("vendor", "jruby", "bin", "jruby")
end

#runtime_jars_root(dir_name, package) ⇒ Object



125
126
127
# File 'lib/logstash/environment.rb', line 125

def runtime_jars_root(dir_name, package)
  ::File.join(dir_name, package, "runtime-jars")
end

#test?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/logstash/environment.rb', line 121

def test?
  env.downcase == "test"
end

#test_jars_root(dir_name, package) ⇒ Object



129
130
131
# File 'lib/logstash/environment.rb', line 129

def test_jars_root(dir_name, package)
  ::File.join(dir_name, package, "test-jars")
end

#windows?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/logstash/environment.rb', line 164

def windows?
  RbConfig::CONFIG['host_os'] =~ WINDOW_OS_RE
end