Module: Capricorn::ExceptionHandler
- Included in:
- Capricorn
- Defined in:
- lib/capricorn/exception_handler.rb
Class Method Summary collapse
- .err ⇒ Object
- .out ⇒ Object
- .redirect_std ⇒ Object
- .setup(out = STDOUT, err = STDERR) ⇒ Object
- .stderr ⇒ Object
- .stdout ⇒ Object
Instance Method Summary collapse
Class Method Details
.err ⇒ Object
26 27 28 |
# File 'lib/capricorn/exception_handler.rb', line 26 def self.err @err end |
.out ⇒ Object
30 31 32 |
# File 'lib/capricorn/exception_handler.rb', line 30 def self.out @out end |
.redirect_std ⇒ Object
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 |
.stderr ⇒ Object
34 35 36 |
# File 'lib/capricorn/exception_handler.rb', line 34 def self.stderr @stderr end |
.stdout ⇒ Object
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 |
#logger ⇒ Object
54 55 56 |
# File 'lib/capricorn/exception_handler.rb', line 54 def logger Capricorn::ExceptionHandler end |
#report ⇒ Object
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 |