Class: Middleman::Logger

Inherits:
ActiveSupport::Logger
  • Object
show all
Defined in:
middleman-core/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


14
15
16
17
18
19
20
21
22
23
# File 'middleman-core/lib/middleman-core/logger.rb', line 14

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

  self.level = log_level
  @instrumenting = is_instrumenting

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

  @mutex = Mutex.new
end

Class Method Details

.singleton(*args) ⇒ Object


5
6
7
8
9
10
11
12
# File 'middleman-core/lib/middleman-core/logger.rb', line 5

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

  @_logger
end

Instance Method Details

#add(*args) ⇒ Object


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

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

#call(message, *args) ⇒ Object


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

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