Module: SilentStream::Enhanced
- Defined in:
- lib/silent_stream.rb
Instance Method Summary collapse
-
#silence_all(switch = true, temporary_level = Logger::ERROR, logger = nil, &block) ⇒ Object
param switch is true or false By default it is true, when means we don’t want logging.
Instance Method Details
#silence_all(switch = true, temporary_level = Logger::ERROR, logger = nil, &block) ⇒ Object
param switch is true or false By default it is true, when means we don’t want logging. Switching it to false enables logging again. By default ERROR log level continues to be logged. The return value is the return value of the block,
so you can use it without changing code structure.
This method is not thread-safe.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/silent_stream.rb', line 25 def silence_all(switch = true, temporary_level = Logger::ERROR, logger = nil, &block) if !switch || silent_stream_no_silence yield else begin logger ||= silent_stream_logger old_logger_level = silent_stream_reset_logger_level(logger, temporary_level) # silence STDOUT (like puts) silence_stream(STDOUT, &block) ensure silent_stream_reset_logger_level(logger, old_logger_level) end end end |