Class: RestFtpDaemon::LoggerPool

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rest-ftp-daemon/logger_pool.rb

Overview

Logger interface class to access logger though symbolic names

Instance Method Summary collapse

Constructor Details

#initializeLoggerPool

Returns a new instance of LoggerPool.



9
10
11
# File 'lib/rest-ftp-daemon/logger_pool.rb', line 9

def initialize
  @loggers = {}
end

Instance Method Details

#create(pipe) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rest-ftp-daemon/logger_pool.rb', line 17

def create pipe
  # Compute file path / STDERR
  logfile = Settings.logs[pipe] if Settings.logs.is_a? Hash
  logfile ||= STDERR

  # Create the logger and return it
  logger = Logger.new(logfile, LOG_ROTATION)   #, 10, 1024000)
  logger.progname = pipe.to_s.upcase

  # And the formatter
  logger.formatter = proc do |severity, datetime, progname, messages|
    # Build common line prefix
    prefix = LOG_FORMAT_PREFIX % [
      datetime.strftime(LOG_FORMAT_TIME),
      severity,
      progname,
    ]

    # If we have a bunch of lines, prefix them and send them together
    if messages.is_a? Array
      messages.map { |line| prefix + line + LOG_NEWLINE}.join
    else
      prefix + messages.to_s + LOG_NEWLINE
    end
  end

  # Finally return this logger
  logger
end

#get(pipe) ⇒ Object



13
14
15
# File 'lib/rest-ftp-daemon/logger_pool.rb', line 13

def get pipe
  @loggers[pipe] ||= create(pipe)
end