A simple module to make logging easier to deal with. It assumes that the logger instance (if not nil) quacks like a Logger object (in Ruby’s standard library). Although used primarily internally by Net::SSH, it can easily be used to add Net::SSH-like logging to your own programs.
class MyClass include Net::SSH::Loggable end Net::SSH.start(...) do |ssh| obj = MyClass.new obj.logger = ssh.logger ... end
Displays the result of yielding if the log level is Logger::DEBUG or greater.
# File lib/net/ssh/loggable.rb, line 24 def debug logger.add(Logger::DEBUG, nil, facility) { yield } if logger && logger.debug? end
Displays the result of yielding if the log level is Logger:ERROR or greater.
# File lib/net/ssh/loggable.rb, line 42 def error logger.add(Logger::ERROR, nil, facility) { yield } if logger && logger.error? end
Displays the result of yielding if the log level is Logger::FATAL or greater.
# File lib/net/ssh/loggable.rb, line 48 def fatal logger.add(Logger::FATAL, nil, facility) { yield } if logger && logger.fatal? end
Generated with the Darkfish Rdoc Generator 2.