Sha256: 08ec10a09a51128648407bf2ba80661c45185d70afdd9d5d3d60fbd0891b4ead

Contents?: true

Size: 1.4 KB

Versions: 49

Compression:

Stored size: 1.4 KB

Contents

require 'sass/logger/log_level'

# 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}.
class Sass::Logger::Delayed < Sass::Logger::Base
  # 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.
  def self.install!
    logger = Sass::Logger::Delayed.new(Sass.logger)
    Sass.logger = logger
    logger
  end

  # Creates a delayed logger wrapping `inner`.
  #
  # @param inner [Sass::Logger::Base] The wrapped logger.
  def initialize(inner)
    self.log_level = inner.log_level
    @inner = inner
    @messages = []
  end

  # Flushes all queued logs to the wrapped logger.
  def flush
    @messages.each {|(l, m)| @inner.log(l, m)}
  end

  # Uninstalls this logger from \{Sass.logger\}. This should only be called if
  # the logger was installed using \{#install!}
  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

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

Version data entries

49 entries across 49 versions & 6 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/sass-3.4.25/lib/sass/logger/delayed.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/sass-3.7.4/lib/sass/logger/delayed.rb
sass-3.7.4 lib/sass/logger/delayed.rb
brakeman-4.4.0 bundle/ruby/2.5.0/gems/sass-3.4.25/lib/sass/logger/delayed.rb
sass-3.7.3 lib/sass/logger/delayed.rb
sass-3.7.2 lib/sass/logger/delayed.rb
sass-3.7.1 lib/sass/logger/delayed.rb
sass-3.7.0 lib/sass/logger/delayed.rb
sass-3.6.0 lib/sass/logger/delayed.rb