Class: Middleman::Logger

Inherits:
ActiveSupport::Logger
  • Object
show all
Defined in:
lib/middleman-core/logger.rb

Overview

The Middleman Logger

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_level = 1, is_instrumenting = false, target = $stdout) ⇒ Logger

Returns a new instance of Logger.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/middleman-core/logger.rb', line 20

def initialize(log_level=1, is_instrumenting=false, target=$stdout)
  super(target)

  self.level = log_level
  @instrumenting = is_instrumenting

  if @instrumenting != false
    ::ActiveSupport::Notifications.subscribe(/\.middleman$/, self)
  end

  @mutex = Mutex.new
end

Class Method Details

.singleton(*args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/middleman-core/logger.rb', line 9

def self.singleton(*args)
  if !@_logger || !args.empty?
    if args.length == 1 && (args.first.is_a?(::String) || args.first.respond_to?(:write))
      args = [0, false, args.first]
    end
    @_logger = new(*args)
  end

  @_logger
end

Instance Method Details

#add(*args) ⇒ Object



33
34
35
36
37
# File 'lib/middleman-core/logger.rb', line 33

def add(*args)
  @mutex.synchronize do
    super
  end
end

#call(message, *args) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/middleman-core/logger.rb', line 39

def call(message, *args)
  return if @instrumenting.is_a?(String) && @instrumenting != 'instrument' && !message.include?(@instrumenting)

  evt = ::ActiveSupport::Notifications::Event.new(message, *args)
  return unless evt.duration > 30
  info "== Instrument (#{evt.name.sub(/.middleman$/, '')}): #{evt.duration}ms\n#{args.last}"
end