Class: Sass::Logger::Base

Inherits:
Object
  • Object
show all
Includes:
LogLevel
Defined in:
lib/sass/logger/base.rb

Direct Known Subclasses

Delayed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_level = :debug, io = nil) ⇒ Base

Returns a new instance of Base.



16
17
18
19
# File 'lib/sass/logger/base.rb', line 16

def initialize(log_level = :debug, io = nil)
  self.log_level = log_level
  self.io = io
end

Instance Attribute Details

#disabled

Returns the value of attribute disabled.



7
8
9
# File 'lib/sass/logger/base.rb', line 7

def disabled
  @disabled
end

#io

Returns the value of attribute io.



8
9
10
# File 'lib/sass/logger/base.rb', line 8

def io
  @io
end

#log_level

Returns the value of attribute log_level.



6
7
8
# File 'lib/sass/logger/base.rb', line 6

def log_level
  @log_level
end

Instance Method Details

#_log(level, message)



40
41
42
43
44
45
46
# File 'lib/sass/logger/base.rb', line 40

def _log(level, message)
  if io
    io.puts(message)
  else
    Kernel.warn(message)
  end
end

#capture

Captures all logger messages emitted during a block and returns them as a string.



27
28
29
30
31
32
33
34
# File 'lib/sass/logger/base.rb', line 27

def capture
  old_io = io
  self.io = StringIO.new
  yield
  io.string
ensure
  self.io = old_io
end

#log(level, message)



36
37
38
# File 'lib/sass/logger/base.rb', line 36

def log(level, message)
  _log(level, message) if logging_level?(level)
end

#logging_level?(level) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/sass/logger/base.rb', line 21

def logging_level?(level)
  !disabled && self.class.log_level?(level, log_level)
end