Class: ActiveSupport::Logger

Inherits:
Logger
  • Object
show all
Includes:
LoggerThreadSafeLevel, LoggerSilence
Defined in:
lib/active_support/logger.rb

Defined Under Namespace

Classes: SimpleFormatter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LoggerSilence

#silence

Methods included from Concern

#append_features, #class_methods, extended, #included

Methods included from LoggerThreadSafeLevel

#after_initialize, #level, #local_level, #local_level=, #local_log_id

Constructor Details

#initialize(*args) ⇒ Logger

Returns a new instance of Logger.



81
82
83
84
85
# File 'lib/active_support/logger.rb', line 81

def initialize(*args)
  super
  @formatter = SimpleFormatter.new
  after_initialize if respond_to? :after_initialize
end

Class Method Details

.broadcast(logger) ⇒ Object

Broadcasts logs to multiple loggers.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/active_support/logger.rb', line 24

def self.broadcast(logger) # :nodoc:
  Module.new do
    define_method(:add) do |*args, &block|
      logger.add(*args, &block)
      super(*args, &block)
    end

    define_method(:<<) do |x|
      logger << x
      super(x)
    end

    define_method(:close) do
      logger.close
      super()
    end

    define_method(:progname=) do |name|
      logger.progname = name
      super(name)
    end

    define_method(:formatter=) do |formatter|
      logger.formatter = formatter
      super(formatter)
    end

    define_method(:level=) do |level|
      logger.level = level
      super(level)
    end

    define_method(:local_level=) do |level|
      logger.local_level = level if logger.respond_to?(:local_level=)
      super(level) if respond_to?(:local_level=)
    end

    define_method(:silence) do |level = Logger::ERROR, &block|
      if logger.respond_to?(:silence)
        logger.silence(level) do
          if defined?(super)
            super(level, &block)
          else
            block.call(self)
          end
        end
      else
        if defined?(super)
          super(level, &block)
        else
          block.call(self)
        end
      end
    end
  end
end

.logger_outputs_to?(logger, *sources) ⇒ Boolean

Returns true if the logger destination matches one of the sources

logger = Logger.new(STDOUT)
ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
# => true

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/active_support/logger.rb', line 17

def self.logger_outputs_to?(logger, *sources)
  logdev = logger.instance_variable_get("@logdev")
  logger_source = logdev.dev if logdev.respond_to?(:dev)
  sources.any? { |source| source == logger_source }
end

Instance Method Details

#add(severity, message = nil, progname = nil, &block) ⇒ Object



87
88
89
90
# File 'lib/active_support/logger.rb', line 87

def add(severity, message = nil, progname = nil, &block)
  return true if @logdev.nil? || (severity || UNKNOWN) < level
  super
end