Class: Sass::Logger::Delayed
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
Class Method Summary collapse
-
.install! ⇒ Sass::Logger::Delayed
Installs a new delayed logger as the current Sass logger, wrapping the original logger.
Instance Method Summary collapse
- #_log(level, message)
-
#flush
Flushes all queued logs to the wrapped logger.
-
#initialize(inner) ⇒ Delayed
constructor
Creates a delayed logger wrapping
inner
. -
#uninstall!
Uninstalls this logger from Sass.logger.
Methods inherited from Base
#capture, #log, #logging_level?
Constructor Details
#initialize(inner) ⇒ Delayed
Creates a delayed logger wrapping inner
.
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!.
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
|