Sha256: 1e60f70d9bc4766edb416a56ec26bd4350c4fb9cc4b667e6d275a8214ae7c30b

Contents?: true

Size: 890 Bytes

Versions: 4

Compression:

Stored size: 890 Bytes

Contents

require 'singleton'
require 'logger'

module RestFtpDaemon
  class LoggerPool
    include Singleton

    def initialize
      @loggers = {}
    end

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

    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, 'daily')   #, 10, 1024000)
      logger.progname = pipe.to_s.upcase
      logger.formatter = proc do |severity, datetime, progname, message|
        # stamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
        stamp = datetime.strftime("%Y-%m-%d %H:%M:%S")
        field_pipe = "%-#{DEFAULT_LOGS_PIPE_LEN.to_i}s" % progname
        "#{stamp}\t#{field_pipe}\t#{message}\n"
      end

      # Finally return this logger
      logger
    end

  private

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.202.2 lib/rest-ftp-daemon/logger_pool.rb
rest-ftp-daemon-0.202.1 lib/rest-ftp-daemon/logger_pool.rb
rest-ftp-daemon-0.202 lib/rest-ftp-daemon/logger_pool.rb
rest-ftp-daemon-0.200 lib/rest-ftp-daemon/logger_pool.rb