Module: RailsSyslogger

Defined in:
lib/rails_syslogger.rb,
lib/rails_syslogger/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
"0.1.6"

Class Method Summary collapse

Class Method Details

.assign_syslogger_by_environment(hostname = default_hostname, facility = Syslog::LOG_LOCAL5) ⇒ Object



15
16
17
# File 'lib/rails_syslogger.rb', line 15

def self.assign_syslogger_by_environment( hostname = default_hostname, facility = Syslog::LOG_LOCAL5 )
  Syslogger.new( hostname, Syslog::LOG_PID, facility ) if should_use_syslog?
end

.default_hostnameObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rails_syslogger.rb', line 21

def default_hostname
  # start with the base application path
  rails_pathname = Pathname.new( ::Rails.root.to_s ).expand_path
  
  # read the symlink if it is a symlink
  # often this will be a symlink of current to releases/<release>
  rails_pathname = rails_pathname.readlink if rails_pathname.symlink?
  
  # get the hostname by backing up two directories
  # this assumes structure of <rails_root>/releases/<release_number>
  hostname = rails_pathname.parent.parent.basename.to_s

  # add 'www.' prefix to hostname if no subdomain
  hostname = 'www.' + hostname unless ( hostname =~ /^devel/ || hostname =~ /^staging/ )
  
  hostname
end

.should_use_syslog?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/rails_syslogger.rb', line 39

def should_use_syslog?
  ENV['RAILS_DEV'] != 'true'
end