Module: OpenHAB::Log
- Defined in:
- lib/openhab/log.rb,
lib/openhab/log.rb
Overview
Provides access to the openHAB logging facilities using Ruby logging methods
Logging is available everywhere through the #logger object.
The logging prefix is org.openhab.automation.jrubyscripting
.
Logging within file-based rules will have the name of the file appended to the logger name. Logging inside of a rule will have the id of the rule appended to the logger name. Any classes will have the full class name appended to the logger name.
Logging within UI-based rules will have the rule UID appended to the logger.
Class Method Summary collapse
-
.logger(object) ⇒ Logger
Retrieve a Logger for a particular object.
Instance Method Summary collapse
-
#logger ⇒ Logger
protected
Retrieve the Logger for this class.
Class Method Details
.logger(object) ⇒ Logger
Retrieve a OpenHAB::Logger for a particular object.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/openhab/log.rb', line 92 def logger(object) case object when Module name = Logger::PREFIX klass = java_klass(object) name += ".#{klass.name.gsub("::", ".")}" if klass.name when String name = object when :main name = "#{Logger::PREFIX}.#{current_file}" name = "#{name}.#{$ctx["ruleUID"]}" if $ctx&.key?("ruleUID") return @loggers[name] ||= BiLogger.new(Logger.new(name)) end @loggers[name] ||= Logger.new(name) end |
Instance Method Details
#logger ⇒ Logger (protected)
Retrieve the OpenHAB::Logger for this class.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/openhab/log.rb', line 72 def logger # no caching on `main` if (instance_of?(Object) && !singleton_methods.empty?) || # also pretend loggers in example groups are in the top-level (defined?(::RSpec::Core::ExampleGroup) && is_a?(Module) && self < ::RSpec::Core::ExampleGroup) return Log.logger(:main) end return @logger ||= Log.logger(self) if equal?(self.class) || is_a?(Module) self.class.logger end |