Class/Module Index [+]

Quicksearch

OpenShift::Runtime::NodeLogger

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

Public Class Methods

context() click to toggle source
# File lib/openshift-origin-node/utils/node_logger.rb, line 123
def self.context
  @context ||= {}
end
create_logger() click to toggle source
# 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
disable() click to toggle source
# File lib/openshift-origin-node/utils/node_logger.rb, line 107
def self.disable
  @logger = NullLogger.new
end
load_config() click to toggle source
# 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
logger() click to toggle source
# File lib/openshift-origin-node/utils/node_logger.rb, line 119
def self.logger
  @logger ||= self.create_logger
end
set_logger(logger) click to toggle source
# File lib/openshift-origin-node/utils/node_logger.rb, line 127
def self.set_logger(logger)
  @logger = logger
end
stderr() click to toggle source
# File lib/openshift-origin-node/utils/node_logger.rb, line 111
def self.stderr
  @logger = StderrLogger.new
end

Public Instance Methods

logger() click to toggle source
# File lib/openshift-origin-node/utils/node_logger.rb, line 115
def logger
  NodeLogger.logger
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.