Class: RestFtpDaemon::LoggerPool
- Inherits:
-
Object
- Object
- RestFtpDaemon::LoggerPool
- 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
- #create(pipe) ⇒ Object
- #get(pipe) ⇒ Object
-
#initialize ⇒ LoggerPool
constructor
A new instance of LoggerPool.
Constructor Details
#initialize ⇒ LoggerPool
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, | # 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 .is_a? Array .map { |line| prefix + line + LOG_NEWLINE}.join else prefix + .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 |