class Sass::Logger::Delayed

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}.

Public Class Methods

install!() click to toggle source

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

This can be undone by calling {#uninstall!}.

@return [Sass::Logger::Delayed] The newly-created logger.

# File lib/sass/logger/delayed.rb, line 16
def self.install!
  logger = Sass::Logger::Delayed.new(Sass.logger)
  Sass.logger = logger
  logger
end
new(inner) click to toggle source

Creates a delayed logger wrapping ‘inner`.

@param inner [Sass::Logger::Base] The wrapped logger.

# File lib/sass/logger/delayed.rb, line 25
def initialize(inner)
  self.log_level = inner.log_level
  @inner = inner
  @messages = []
end

Public Instance Methods

_log(level, message) click to toggle source
# File lib/sass/logger/delayed.rb, line 47
def _log(level, message)
  @messages << [level, message]
end
flush() click to toggle source

Flushes all queued logs to the wrapped logger.

# File lib/sass/logger/delayed.rb, line 32
def flush
  @messages.each {|(l, m)| @inner.log(l, m)}
end
uninstall!() click to toggle source

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

# 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