This class provides a central logging facility for all node operations.
The specific logger implementation used is created lazily upon first reference to logger. The logger implementation is obtained by reading the PLATFORM_LOG_CLASS key from +OpenShift::Config+, which is assumed to be the string name of the logger class to instantiate. The class is assumed to be in the +OpenShift::Runtime::NodeLogger+ module.
If no logger class is configured, the +OpenShift::Runtime::NodeLogger::SplitTraceLogger+ will be used by default.
Logger implementations are expected to confirm to the following simple interface:
module OpenShift
module NodeLogger
class CustomLogger
def initialize(config, context); end
def info(*args, &block); end
def warn(*args, &block); end
def error(*args, &block); end
def fatal(*args, &block); end
def debug(*args, &block); end
def trace(*args, &block); end
def reinitialize; end
end
end
end
NodeLogger maintains a context Hash which is passed to logger implementations. Callers may set and remove keys from the context at-will, to provide information such as transaction IDs or any other data which may be useful for loggers. The context object is NOT thread-safe.
A disable method is provided for convenience to initialize NodeLogger with the NullLogger, effectively disabling logging. This is equivalent to using external configuration, but provides a programmatic entrypoint.
Example:
require 'node_logger'
NodeLogger.logger.warn "A warning"
NodeLogger.logger.info { "A deferred-evaluation log message" }
NodeLogger.context[:tx_id] = 1234
NodeLogger.context.delete(:tx_id)
class MyClass
include NodeLogger
def fun
logger.debug "A message"
end
end
# File lib/openshift-origin-node/utils/node_logger.rb, line 123 def self.context @context ||= {} end
# File lib/openshift-origin-node/utils/node_logger.rb, line 86 def self.create_logger config = self.load_config logger_class = config.get("PLATFORM_LOG_CLASS") || DEFAULT_LOGGER_CLASS begin logger = ::OpenShift::Runtime::NodeLogger.const_get(logger_class).new(config, self.context) rescue => e raise "Couldn't create NodeLogger class #{logger_class}: #{e.message}" end logger end
# File lib/openshift-origin-node/utils/node_logger.rb, line 107 def self.disable @logger = NullLogger.new end
# File lib/openshift-origin-node/utils/node_logger.rb, line 99 def self.load_config begin config = ::OpenShift::Config.new rescue => e raise "Couldn't load NodeLogger configuration: #{e.message}" end end
# File lib/openshift-origin-node/utils/node_logger.rb, line 119 def self.logger @logger ||= self.create_logger end
Generated with the Darkfish Rdoc Generator 2.