class BatchKit::LogManager

Used for setting the log framework to use, and retrieving a logger from the current framework.

Public Class Methods

configure(options = {}) click to toggle source
# File lib/batch-kit/logging.rb, line 44
def configure(options = {})
    self.log_framework = options[:log_framework] if options[:log_framework]
    if options.fetch(:log_color, true)
        case self.log_framework
        when :log4r
            require 'color_console/log4r_logger'
            Console.replace_console_logger(logger: 'batch')
        when :java_util_logging
            require 'color_console/java_util_logger'
            Console.replace_console_logger(
                level: Java::JavaUtilLogging::Level::FINE,
                level_labels: {
                    Java::JavaUtilLogging::Level::FINE => 'DETAIL',
                    Java::JavaUtilLogging::Level::FINER => 'TRACE'
                })
        else
            require 'color_console'
        end
    end
end
level() click to toggle source

Returns the current root log level

# File lib/batch-kit/logging.rb, line 102
def level
    logger.level
end
level=(level) click to toggle source

Sets the log level

# File lib/batch-kit/logging.rb, line 108
def level=(level)
    case log_framework
    when :log4r
        lvl = Log4r::LNAMES.index(level.to_s.upcase)
        Log4r::Logger.each_logger{ |l| l.level = lvl }
    else
        logger.level = level
    end
end
log_framework() click to toggle source

Returns a symbol identifying which logging framework is being used.

# File lib/batch-kit/logging.rb, line 67
def log_framework
    unless @log_framework
        if RUBY_PLATFORM == 'java'
            LogManager.log_framework = :java_util_logging
        else
            begin
                require 'log4r'
                LogManager.log_framework = :log4r
            rescue LoadError
                LogManager.log_framework = :stdout
            end
        end
    end
    @log_framework
end
log_framework=(framework) click to toggle source

Sets the logging framework

# File lib/batch-kit/logging.rb, line 85
def log_framework=(framework)
    unless Logging::FRAMEWORKS.include?(framework)
        raise ArgumentError, "Unknown logging framework #{framework.inspect}"
    end
    if @log_framework
        lvl = self.level
    end
    @log_framework = framework
    if init_proc = Logging::FRAMEWORK_INIT[@log_framework]
        init_proc.call
    end
    self.level = lvl if lvl
    logger.trace "Log framework is #{@log_framework}"
end
logger(name = nil) click to toggle source

Returns a logger with a given name, which must be under the 'batch' namespace. If name is omitted, the logger is named 'batch'. If a name is specified that is not under 'batch', then it is prepended with 'batch'.

@return [Logger] a logger object that can be used for generating

log messages. The type of logger returned will depend on the
log framework being used, but the logger is guaranteed to
implement the following log methods:
- error
- warning
- info
- config
- detail
- trace
- debug
# File lib/batch-kit/logging.rb, line 135
def logger(name = nil)
    case name
    when NilClass, ''
        name = 'batch'
    when /^batch/
    when /\./
    when String
        name = "batch.#{name}"
    end
    case log_framework
    when :stdout
        BatchKit::Logging::StdOutLogger.logger(name)
    when :java_util_logging
        BatchKit::Logging::JavaLogFacade.new(Java::JavaUtilLogging::Logger.getLogger(name))
    when :log4r
        log4r_name = name.gsub('.', '::')
        BatchKit::Logging::Log4rFacade.new(Log4r::Logger[log4r_name] ||
                                        Log4r::Logger.new(log4r_name))
    else BatchKit::Logging::NullLogger.instance
    end
end