Class: Sass::Logger::Delayed
- Inherits:
-
Base
- Object
- Base
- Sass::Logger::Delayed
- Defined in:
- .ruby-sass/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
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) ⇒ Object
-
#flush ⇒ Object
Flushes all queued logs to the wrapped logger.
-
#initialize(inner) ⇒ Delayed
constructor
Creates a delayed logger wrapping `inner`.
-
#uninstall! ⇒ Object
Uninstalls this logger from Sass.logger.
Methods inherited from Base
#capture, #log, #logging_level?
Methods included from LogLevel
Constructor Details
#initialize(inner) ⇒ Delayed
Creates a delayed logger wrapping `inner`.
25 26 27 28 29 |
# File '.ruby-sass/lib/sass/logger/delayed.rb', line 25 def initialize(inner) self.log_level = inner.log_level @inner = inner @messages = [] end |
Constructor Details
#initialize(inner) ⇒ Delayed
Creates a delayed logger wrapping `inner`.
25 26 27 28 29 |
# File '.ruby-sass/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 '.ruby-sass/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) ⇒ Object
47 48 49 |
# File '.ruby-sass/lib/sass/logger/delayed.rb', line 47 def _log(level, ) @messages << [level, ] end |
#flush ⇒ Object
Flushes all queued logs to the wrapped logger.
32 33 34 |
# File '.ruby-sass/lib/sass/logger/delayed.rb', line 32 def flush @messages.each {|(l, m)| @inner.log(l, m)} end |
#uninstall! ⇒ Object
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 '.ruby-sass/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 |