Class: Middleman::Logger

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

Overview

The Middleman Logger

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Logger.



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

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

Instance Method Details

#add(*args) ⇒ Object



23
24
25
26
27
# File 'lib/middleman-core/logger.rb', line 23

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

#call(message, *args) ⇒ Object



29
30
31
32
33
34
# File 'lib/middleman-core/logger.rb', line 29

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

  evt = ActiveSupport::Notifications::Event.new(message, *args)
  self.info "== Instrument (#{evt.name.sub(/.middleman$/, '')}): #{evt.duration}ms"
end