Class: Sass::Logger::Delayed

Inherits:
Base
  • Object
show all
Defined in:
lib/sass/logger/delayed.rb

Overview

A logger that delays messages until they're explicitly flushed to an inner logger.

This can be installed around the current logger by calling #install!, and the original logger can be replaced by calling #uninstall!. The log messages can be flushed by calling #flush.

Instance Attribute Summary

Attributes inherited from Base

#disabled, #io, #log_level

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#capture, #log, #logging_level?

Constructor Details

#initialize(inner) ⇒ Delayed

Creates a delayed logger wrapping inner.

Parameters:



25
26
27
28
29
# File 'lib/sass/logger/delayed.rb', line 25

def initialize(inner)
  self.log_level = inner.log_level
  @inner = inner
  @messages = []
end

Class Method Details

.install!Sass::Logger::Delayed

Installs a new delayed logger as the current Sass logger, wrapping the original logger.

This can be undone by calling #uninstall!.

Returns:



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

def self.install!
  logger = Sass::Logger::Delayed.new(Sass.logger)
  Sass.logger = logger
  logger
end

Instance Method Details

#_log(level, message)



47
48
49
# File 'lib/sass/logger/delayed.rb', line 47

def _log(level, message)
  @messages << [level, message]
end

#flush

Flushes all queued logs to the wrapped logger.



32
33
34
# File 'lib/sass/logger/delayed.rb', line 32

def flush
  @messages.each {|(l, m)| @inner.log(l, m)}
end

#uninstall!

Uninstalls this logger from Sass.logger. This should only be called if the logger was installed using #install!



38
39
40
41
42
43
44
45
# File 'lib/sass/logger/delayed.rb', line 38

def uninstall!
  if Sass.logger != self
    throw Exception.new("Can't uninstall a logger that's not currently installed.")
  end

  @inner.log_level = log_level
  Sass.logger = @inner
end