Class: LoggerExtension::MultiIOLogger

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/logger_extension/multi_i_o_logger.rb

Defined Under Namespace

Classes: LogDeviceMutex

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*targets) ⇒ MultiIOLogger

Returns a new instance of MultiIOLogger.



13
14
15
16
17
# File 'lib/logger_extension/multi_i_o_logger.rb', line 13

def initialize(*targets)
  @targets = targets.each { |target| target.sync = true if target.respond_to?(:sync=) }
  @default_formatter = ::LoggerExtension::Formatter.new
  @mutex = LogDeviceMutex.new
end

Instance Attribute Details

#default_formatterObject (readonly)

Returns the value of attribute default_formatter.



10
11
12
# File 'lib/logger_extension/multi_i_o_logger.rb', line 10

def default_formatter
  @default_formatter
end

#default_prognameObject

Returns the value of attribute default_progname.



11
12
13
# File 'lib/logger_extension/multi_i_o_logger.rb', line 11

def default_progname
  @default_progname
end

Instance Method Details

#closeObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/logger_extension/multi_i_o_logger.rb', line 38

def close
  @targets.each do |target|
    begin
      @mutex.synchronize do
        target.close rescue nil
      end
    rescue Exception
      target.close rescue nil
    end
  end
end

#write(*arguments) ⇒ Object



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

def write(*arguments)
  @targets.each { |target|
     begin
      @mutex.synchronize do
        begin
          target.write(*arguments)
        rescue
          log_exception('WARN', 'log writing failed.--->', $!)
        end
      end
    rescue Exception => ignored
      log_exception('WARN', 'log writing failed.--->', ignored)
    end
  }
end