Module: Daemon::Utils::Loggable
- Included in:
- Callbacks, Coordinator, ManagementCommands, MasterProcess::StopService, Messaging::ConnectionManager, Runner::StopService, Supervision, Supervision::Definition::Handler, Supervision::MessagesManager, Supervision::Registry, AutoDeletedHash
- Defined in:
- lib/onapp/engine/utils/loggable.rb
Overview
Stolen from github.com/net-ssh/net-ssh
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 Daemon::Utils::Loggable
end
obj = MyClass.new
obj.logger = ssh.logger
...
Instance Attribute Summary (collapse)
-
- (Object) logger
The logger instance that will be used to log messages.
Instance Method Summary (collapse)
-
- (Object) debug
Displays the result of yielding if the log level is Logger::DEBUG or greater.
-
- (Object) error
Displays the result of yielding if the log level is Logger:ERROR or greater.
-
- (Object) fatal
Displays the result of yielding if the log level is Logger::FATAL or greater.
-
- (Object) info
Displays the result of yielding if the log level is Logger::INFO or greater.
-
- (Object) lwarn
Displays the result of yielding if the log level is Logger::WARN or greater.
Instance Attribute Details
- (Object) logger
The logger instance that will be used to log messages. If nil, nothing will be logged.
21 22 23 |
# File 'lib/onapp/engine/utils/loggable.rb', line 21 def logger @logger end |
Instance Method Details
- (Object) debug
Displays the result of yielding if the log level is Logger::DEBUG or greater.
25 26 27 |
# File 'lib/onapp/engine/utils/loggable.rb', line 25 def debug logger.add(Logger::DEBUG, nil, facility) { yield } if logger && logger.debug? end |
- (Object) error
Displays the result of yielding if the log level is Logger:ERROR or greater.
43 44 45 |
# File 'lib/onapp/engine/utils/loggable.rb', line 43 def error logger.add(Logger::ERROR, nil, facility) { yield } if logger && logger.error? end |
- (Object) fatal
Displays the result of yielding if the log level is Logger::FATAL or greater.
49 50 51 |
# File 'lib/onapp/engine/utils/loggable.rb', line 49 def fatal logger.add(Logger::FATAL, nil, facility) { yield } if logger && logger.fatal? end |
- (Object) info
Displays the result of yielding if the log level is Logger::INFO or greater.
31 32 33 |
# File 'lib/onapp/engine/utils/loggable.rb', line 31 def info logger.add(Logger::INFO, nil, facility) { yield } if logger && logger.info? end |
- (Object) lwarn
Displays the result of yielding if the log level is Logger::WARN or greater. (Called lwarn to avoid shadowing with Kernel#warn.)
37 38 39 |
# File 'lib/onapp/engine/utils/loggable.rb', line 37 def lwarn logger.add(Logger::WARN, nil, facility) { yield } if logger && logger.warn? end |