class BatchKit::Logging::JavaLogFacade

Constants

LEVEL_MAP

Attributes

log_file[R]

@return The path to any log file used with this logger

Public Class Methods

new(logger) click to toggle source
# File lib/batch-kit/logging/java_util_logger.rb, line 24
def initialize(logger)
    @java_logger = logger
end

Public Instance Methods

level() click to toggle source
# File lib/batch-kit/logging/java_util_logger.rb, line 29
def level
    LEVEL_MAP.invert[@java_logger.getLevel()]
end
level=(level) click to toggle source
# File lib/batch-kit/logging/java_util_logger.rb, line 34
def level=(level)
    @java_logger.setLevel(LEVEL_MAP[level])
end
log_file=(log_path) click to toggle source

Adds a FileHandler to capture output from this logger to a log file.

# File lib/batch-kit/logging/java_util_logger.rb, line 40
def log_file=(log_path)
    @java_logger.getHandlers().each do |h|
        if h.is_a?(Java::JavaUtilLogging::FileHandler)
            @java_logger.removeHandler(h)
            h.close()
        end
    end
    @log_file = log_path
    if log_path
        # Java logger does not follow changes in working directory via Dir.chdir
        log_path = File.absolute_path(log_path)
        FileUtils.mkdir_p(File.dirname(log_path))
        fh = Java::JavaUtilLogging::FileHandler.new(log_path, true)
        if defined?(Console::JavaUtilLogger)
            fmt = Console::JavaUtilLogger::RubyFormatter.new('[%1$tF %1$tT]  %4$-6s  %5$s', -1)
            fmt.level_labels[Java::JavaUtilLogging::Level::FINE] = 'DETAIL'
            fmt.level_labels[Java::JavaUtilLogging::Level::FINER] = 'TRACE'
        else
            fmt = Java::JavaUtilLogging::SimpleFormatter.new
        end
        fh.setFormatter(fmt)
        self.addHandler(fh)
    end
end
method_missing(mthd, *args) click to toggle source
# File lib/batch-kit/logging/java_util_logger.rb, line 78
def method_missing(mthd, *args)
    @java_logger.send(mthd, *args)
end