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 anem
appended to the logger name.
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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/openhab/log.rb', line 79 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}.#{rules_file.tr_s(":", "_").gsub(/[^A-Za-z0-9_.-]/, "")}" 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.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/openhab/log.rb', line 59 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 |