Sha256: 86a36307279609b8aecd29b660406f5b483eb67f0c03e6cd8c89df9a46b7bb42

Contents?: true

Size: 1.51 KB

Versions: 30

Compression:

Stored size: 1.51 KB

Contents

module Capricorn
  module ExceptionHandler
    
    def self.setup(out=STDOUT, err=STDERR)
      if String === out
        @out    = Logger.new(out, 'daily')
        @stdout = @out.instance_variable_get('@logdev').instance_variable_get('@dev')
      else
        @out    = Logger.new(out)
        @stdout = out
      end
      
      if String === err
        @err = Logger.new(err, 'daily')
        @stderr = @err.instance_variable_get('@logdev').instance_variable_get('@dev')
      else
        @err    = Logger.new(err)
        @stderr = err
      end
      
      @out.level = Logger::DEBUG
      @err.level = Logger::DEBUG
    end
    
    def self.err
      @err
    end
    
    def self.out
      @out
    end
    
    def self.stderr
      @stderr
    end
    
    def self.stdout
      @stdout
    end
    
    def self.redirect_std
      if STDOUT != self.stdout
        STDOUT.reopen self.stdout
      end
      
      if STDERR != self.stderr
        STDERR.reopen self.stderr
      end
      
      STDIN.reopen "/dev/null"
    end
    
    def logger
      Capricorn::ExceptionHandler
    end
    
    def log(*args, &block)
      args = [args.inspect] if args.size == 1 and Array === args.first
      logger.out.info(*args, &block)
    end
    
    def report
      yield
    rescue Exception => e
      if StandardError === e
        logger.err.error(e)
      else
        logger.err.fatal(e)
      end
      raise e
    end
    
  end
end

def FileUtils.fu_output_message(msg)
  Capricorn::ExceptionHandler.out.info(msg)
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
simonmenke-capricorn-0.2.03 lib/capricorn/exception_handler.rb
simonmenke-capricorn-0.2.07 lib/capricorn/exception_handler.rb
simonmenke-capricorn-0.2.25 lib/capricorn/exception_handler.rb
simonmenke-capricorn-0.2.26 lib/capricorn/exception_handler.rb
capricorn-0.2.25 lib/capricorn/exception_handler.rb
capricorn-0.2.24 lib/capricorn/exception_handler.rb
capricorn-0.2.23 lib/capricorn/exception_handler.rb
capricorn-0.2.22 lib/capricorn/exception_handler.rb
capricorn-0.2.21 lib/capricorn/exception_handler.rb
capricorn-0.2.20 lib/capricorn/exception_handler.rb
capricorn-0.2.19 lib/capricorn/exception_handler.rb
capricorn-0.2.18 lib/capricorn/exception_handler.rb
capricorn-0.2.17 lib/capricorn/exception_handler.rb
capricorn-0.2.16 lib/capricorn/exception_handler.rb
capricorn-0.2.15 lib/capricorn/exception_handler.rb
capricorn-0.2.14 lib/capricorn/exception_handler.rb
capricorn-0.2.13 lib/capricorn/exception_handler.rb
capricorn-0.2.12 lib/capricorn/exception_handler.rb
capricorn-0.2.11 lib/capricorn/exception_handler.rb
capricorn-0.2.10 lib/capricorn/exception_handler.rb