Sha256: 82217127a60f3fa6bbacb69606f4848e834a81f0352a833e7980ed51c6a28368

Contents?: true

Size: 771 Bytes

Versions: 6

Compression:

Stored size: 771 Bytes

Contents

require 'log4r'

module HackBoxen
  module Logging
    include Log4r
    include Paths

    def logs_to *args
      @log = Logger.new('hackbox_logger')
      @log.outputters = args.map do |location|
        l = create_log(location)
        l.formatter = default_format
        l
      end
      def log
        @log
      end
    end

    private

    def default_format
      PatternFormatter.new(:pattern =>"[%l] %d :: %m")
    end

    def default_file
      { :filename => File.join(path_to(:log_dir), 'hb-log'), :trunc => false }
    end

    def create_log location
      case location
      when STDOUT then Outputter.stdout
      when STDERR then Outputter.stderr
      when 'file' then FileOutputter.new('hb_log_file', default_file)
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hackboxen-0.1.5 lib/hackboxen/utils/logging.rb
hackboxen-0.1.4 lib/hackboxen/utils/logging.rb
hackboxen-0.1.3 lib/hackboxen/utils/logging.rb
hackboxen-0.1.2 lib/hackboxen/utils/logging.rb
hackboxen-0.1.1 lib/hackboxen/utils/logging.rb
hackboxen-0.1.0 lib/hackboxen/utils/logging.rb