Sha256: f282d5777c01146f939ca8a249728fe90f8413b0918cc025ec17971a6552ba6d

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 KB

Contents

# Copyright:: (c) Autotelik Media Ltd 2012
# Author ::   Tom Statter
# Date ::     Aug 2012
# License::   Free, Open Source. MIT.
#
# Details::   Logging facilities for datashift.
#
require 'fileutils'
  
module DataShift

  module Logging
    
    class MultiIO
           
      def initialize(*targets)
        @targets = []
        targets.each {|t| @targets << Logger.new(t) }
      end

      def add(target)
        @targets << Logger.new(target)
      end
      
      
      def method_missing(method, *args, &block)
        @targets.each {|t| t.send(method, *args, &block) }
      end
    
      def verbose
        add(STDOUT)
      end
    
    end
    
    require 'logger'
     
    def logdir
      @logdir ||= 'log'
      @logdir
    end
  
    def logger
      @logger ||= open
      @logger
    end
    
    private
    
    def open( log = 'datashift.log')
      return ActiveRecord::Base.logger if(defined?(ActiveRecord) && ActiveRecord::Base.logger)
      FileUtils::mkdir(logdir) unless File.directory?(logdir)
      log_file = File.open( File.join(logdir(), 'datashift.log'), "a")
      MultiIO.new(log_file)
    end
  end
  
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
datashift-0.16.0 lib/datashift/logging.rb
datashift-0.15.0 lib/datashift/logging.rb
datashift-0.14.0 lib/datashift/logging.rb
datashift-0.13.0 lib/datashift/logging.rb
datashift-0.12.1 lib/datashift/logging.rb
datashift-0.12.0 lib/datashift/logging.rb
datashift-0.11.1 lib/datashift/logging.rb
datashift-0.11.0 lib/datashift/logging.rb
datashift-0.10.2 lib/datashift/logging.rb
datashift-0.10.1 lib/datashift/logging.rb
datashift-0.10.0 lib/datashift/logging.rb
datashift-0.9.0 lib/datashift/logging.rb
datashift-0.8.0 lib/datashift/logging.rb
datashift-0.7.0 lib/datashift/logging.rb
datashift-0.6.1 lib/datashift/logging.rb
datashift-0.6.0 lib/datashift/logging.rb
datashift-0.5.0 lib/datashift/logging.rb
datashift-0.4.3 lib/datashift/logging.rb
datashift-0.4.2 lib/datashift/logging.rb
datashift-0.4.0 lib/datashift/logging.rb