Module: Shared::LoggerHelper

Included in:
PushyDaemon::Endpoint
Defined in:
lib/shared/logger_helper.rb

Constant Summary collapse

CONFIG_PATH =
:path

Instance Method Summary collapse

Instance Method Details

#logfile(config, pipe) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/shared/logger_helper.rb', line 7

def logfile config, pipe
  # Disabled if no valid config
  return nil unless config.is_a?(Hash)

  # Compute logfile and check if we can write there
  logfile = File.expand_path(config[pipe].to_s, config[CONFIG_PATH].to_s)

  # Check that we'll be able to create logfiles
  if File.exists?(logfile)
    # File is there, is it writable ?
    unless File.writable?(logfile)
      puts "LoggerHelper [#{pipe}] disabled: file not writable [#{logfile}]"
      return nil
    end
  else
    # No file here, can we create it ?
    logdir = File.dirname(logfile)
    unless File.writable?(logdir)
      puts "LoggerHelper [#{pipe}] disabled: directory not writable [#{logdir}]"
      return nil
    end
  end

  # OK, return a clean file path
  puts "LoggerHelper [#{pipe}] logging to [#{logfile}]"
  return logfile
end