Class: ErrorHandler::EH
- Inherits:
-
Object
- Object
- ErrorHandler::EH
- Defined in:
- lib/eh/eh.rb
Constant Summary collapse
- EX_OK =
0- EX_GENERAL =
1- EX_BASE =
base value for error messages
64- EX_USAGE =
command line usage error
64- EX_DATAERR =
data format error
65- EX_NOINPUT =
cannot open input
66- EX_NOUSER =
addressee unknown
67- EX_NOHOST =
host name unknown
68- EX_UNAVAILABLE =
service unavailable
69- EX_SOFTWARE =
internal software error
70- EX_OSERR =
system error (e.g., can’t fork)
71- EX_OSFILE =
critical OS file missing
72- EX_CANTCREAT =
/* can’t create (user) output file
73- EX_IOERR =
input/output error
74- EX_TEMPFAIL =
temp failure; user is invited to retry
75- EX_PROTOCOL =
remote error in protocol
76- EX_NOPERM =
permission denied
77- EX_CONFIG =
configuration error
78- ERROR =
'error'- DEBUG =
'debug'- INFO =
'info'- WARN =
'warn'- FATAL =
'fatal'
Class Method Summary collapse
- .generate_log_id ⇒ Object
- .log(facilities, msg, msg_type) ⇒ Object
- .report_unhandled(logfile = nil, handlers = nil) ⇒ Object
- .retry(options, &block) ⇒ Object
- .retry!(options, &block) ⇒ Object
- .run(options, &block) ⇒ Object
- .run!(options, &block) ⇒ Object
Class Method Details
.generate_log_id ⇒ Object
105 106 107 |
# File 'lib/eh/eh.rb', line 105 def self.generate_log_id ms = Time.now end |
.log(facilities, msg, msg_type) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/eh/eh.rb', line 97 def self.log(facilities, msg, msg_type) if facilities.is_a? Array EH::log_multiple_loggers(facilities, msg, msg_type) else EH::log_single_logger(facilities, msg, msg_type) end end |
.report_unhandled(logfile = nil, handlers = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/eh/eh.rb', line 28 def self.report_unhandled(logfile = nil, handlers = nil) if $! = "Unhandled exception: #{$!}" warn if not logfile.nil? open(logfile, 'a') { |f| f.puts } end handle(handlers, $!, ) if not handlers.nil? end end |
.retry(options, &block) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/eh/eh.rb', line 55 def self.retry(, &block) opts = || {} begin EH::retry_with_raise(opts, block) return true rescue => e msg = "#{opts[:message]}: #{e.}" if not opts[:logger].nil? EH::log(opts[:logger], msg, EH::log_level(opts)) if opts[:exception_filter].nil? or opts[:exception_filter].include? e.class end EH::handle(opts[:handlers], e, msg) if not opts[:handlers].nil? return false end end |
.retry!(options, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/eh/eh.rb', line 42 def self.retry!(, &block) opts = || {} EH::retry_with_raise(opts, block) rescue => e raise e if opts.nil? == false and opts[:exception_filter] and not opts[:exception_filter].include? e.class msg = "#{opts[:message]}: #{e.}" EH::log(opts[:logger], msg, EH::log_level(opts)) if opts.nil? == false and not opts[:logger].nil? and not opts[:message].nil? EH::handle(opts[:handlers], e, msg) if not opts[:handlers].nil? raise e end |
.run(options, &block) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/eh/eh.rb', line 85 def self.run(, &block) opts = || {} block.call(EH::construct_args(opts)) rescue => e msg = "#{opts[:message]}: #{e.}" if not opts[:logger].nil? EH::log(opts[:logger], msg, EH::log_level(opts)) if opts[:exception_filter].nil? or opts[:exception_filter].include? e.class end EH::handle(opts[:handlers], e, msg) if not opts[:handlers].nil? end |
.run!(options, &block) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/eh/eh.rb', line 70 def self.run!(, &block) opts = || {} block.call(EH::construct_args(opts)) rescue => e msg = "#{opts[:message]}: #{e.}" if not opts[:logger].nil? EH::log(opts[:logger], msg, EH::log_level(opts)) if opts[:exception_filter].nil? or opts[:exception_filter].include? e.class end EH::handle(opts[:handlers], e, msg) if not opts[:handlers].nil? raise e if opts.nil? == false and opts[:exception_filter] and not opts[:exception_filter].include? e.class raise e if opts.nil? == true or opts[:exception_filter].nil? == true or opts[:exception_filter] == [] end |