Module: Capricorn::ExceptionHandler

Included in:
Capricorn
Defined in:
lib/capricorn/exception_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.errObject



26
27
28
# File 'lib/capricorn/exception_handler.rb', line 26

def self.err
  @err
end

.outObject



30
31
32
# File 'lib/capricorn/exception_handler.rb', line 30

def self.out
  @out
end

.redirect_stdObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/capricorn/exception_handler.rb', line 42

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

.setup(out = STDOUT, err = STDERR) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/capricorn/exception_handler.rb', line 5

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

.stderrObject



34
35
36
# File 'lib/capricorn/exception_handler.rb', line 34

def self.stderr
  @stderr
end

.stdoutObject



38
39
40
# File 'lib/capricorn/exception_handler.rb', line 38

def self.stdout
  @stdout
end

Instance Method Details

#log(*args, &block) ⇒ Object



58
59
60
# File 'lib/capricorn/exception_handler.rb', line 58

def log(*args, &block)
  logger.out.info(*args, &block)
end

#loggerObject



54
55
56
# File 'lib/capricorn/exception_handler.rb', line 54

def logger
  Capricorn::ExceptionHandler
end

#reportObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/capricorn/exception_handler.rb', line 62

def report
  yield
rescue Exception => e
  if StandardError === e
    logger.err.error(e)
  else
    logger.err.fatal(e)
  end
  raise e
end