Module: Net::SSH::Loggable
- Included in:
- Authentication::Agent, Authentication::KeyManager, Authentication::Methods::Abstract, Authentication::Session, BufferedIo, Connection::Channel, Connection::Session, Service::Forward, Transport::Algorithms, Transport::Kex::DiffieHellmanGroup1SHA1, Transport::ServerVersion, Transport::Session
- Defined in:
- lib/net/ssh/loggable.rb
Overview
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
Instance Attribute Summary collapse
-
#logger ⇒ Object
The logger instance that will be used to log messages.
Instance Method Summary collapse
-
#debug ⇒ Object
Displays the result of yielding if the log level is Logger::DEBUG or greater.
-
#error ⇒ Object
Displays the result of yielding if the log level is Logger:ERROR or greater.
-
#fatal ⇒ Object
Displays the result of yielding if the log level is Logger::FATAL or greater.
-
#info ⇒ Object
Displays the result of yielding if the log level is Logger::INFO or greater.
-
#lwarn ⇒ Object
Displays the result of yielding if the log level is Logger::WARN or greater.
Instance Attribute Details
#logger ⇒ Object
The logger instance that will be used to log messages. If nil, nothing will be logged.
20 21 22 |
# File 'lib/net/ssh/loggable.rb', line 20 def logger @logger end |
Instance Method Details
#debug ⇒ Object
Displays the result of yielding if the log level is Logger::DEBUG or greater.
24 25 26 |
# File 'lib/net/ssh/loggable.rb', line 24 def debug logger.add(Logger::DEBUG, nil, facility) { yield } if logger end |
#error ⇒ Object
Displays the result of yielding if the log level is Logger:ERROR or greater.
42 43 44 |
# File 'lib/net/ssh/loggable.rb', line 42 def error logger.add(Logger::ERROR, nil, facility) { yield } if logger end |
#fatal ⇒ Object
Displays the result of yielding if the log level is Logger::FATAL or greater.
48 49 50 |
# File 'lib/net/ssh/loggable.rb', line 48 def fatal logger.add(Logger::FATAL, nil, facility) { yield } if logger end |
#info ⇒ Object
Displays the result of yielding if the log level is Logger::INFO or greater.
30 31 32 |
# File 'lib/net/ssh/loggable.rb', line 30 def info logger.add(Logger::INFO, nil, facility) { yield } if logger end |
#lwarn ⇒ Object
Displays the result of yielding if the log level is Logger::WARN or greater. (Called lwarn to avoid shadowing with Kernel#warn.)
36 37 38 |
# File 'lib/net/ssh/loggable.rb', line 36 def lwarn logger.add(Logger::WARN, nil, facility) { yield } if logger end |