Sha256: 833520dba1f73a3765dc32c94d6b400b4210e5b53acdb210e9b9e7cc79dda349

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

require 'tee_logger/version'
require 'tee_logger/constants'

require 'logger'

# namespace
module TeeLogger
  # shortcut for TeeLogger::TeeLogger.new
  def self.new(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
    TeeLogger.new(logdev, shift_age, shift_size)
  end

  # main
  class TeeLogger
    attr_reader :logger, :console

    def initialize(logdev = DEFAULT_FILE, shift_age = 0, shift_size = 1_048_576)
      @logger  = Logger.new(logdev, shift_age, shift_size)
      @console = Logger.new($stdout)
    end

    # logging methods.
    LOGGING_METHODS.each do |name|
      define_method(name) do |progname = nil, &block|
        @logger.send(name, progname, &block)
        @console.send(name, progname, &block)
      end
    end

    # check logging level methods.
    LOGGING_METHODS.map { |v| "#{v}?" }.each do |name|
      define_method(name) do
        # TODO: which?
        # @logger.send(name)
        @console.send(name)
      end
    end

    # TODO: Too miscellaneous
    def disable(target)
      instance_variable_get("@#{target}").formatter = proc { |s, dt, p, m| }
    end

    # TODO: Too miscellaneous
    def enable(target)
      instance_variable_get("@#{target}").formatter = Logger::Formatter.new
    end

    def progname
      # TODO: which?
      # @logger.progname
      @console.progname
    end

    def progname=(name = nil)
      # TODO: which?
      # @logger.progname  = name
      @console.progname = name
    end

    def formatter
      # TODO: which?
      # @logger.formatter
      @console.formatter
    end

    def formatter=(formatter)
      @logger.formatter  = formatter
      @console.formatter = formatter
    end

    # def close
    #   @logger.close
    #   # @console.close
    # end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tee_logger-2.2.0 lib/tee_logger.rb