Module: Skutil::Base
- Defined in:
- lib/skutil.rb
Instance Method Summary collapse
- #debug(message) ⇒ Object
- #error(message) ⇒ Object
- #execute(&process) ⇒ Object
- #info(message) ⇒ Object
- #log(log_type, message, is_base_info = true) ⇒ Object
- #warn(message) ⇒ Object
Instance Method Details
#debug(message) ⇒ Object
35 36 37 38 39 |
# File 'lib/skutil.rb', line 35 def debug() if $IS_DEBUG log(:DEBUG,) end end |
#error(message) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/skutil.rb', line 20 def error() if .is_a? Exception log(:ERROR," #{.}") .backtrace.each_with_index {|line, i| log(:ERROR," #{line})",false) } else log(:ERROR,.to_s) end end |
#execute(&process) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/skutil.rb', line 41 def execute(&process) info "start script" script_started_at = Time.now begin return yield process rescue => e error e Skutil::Mail.send_error(ERROR_MAIL_FROM,ERROR_MAIL_TO,ERROR_MAIL_SUBJECT,e) return e ensure info "finish script (#{Time.now - script_started_at}sec)" end end |
#info(message) ⇒ Object
16 17 18 |
# File 'lib/skutil.rb', line 16 def info() log(:INFO,) end |
#log(log_type, message, is_base_info = true) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/skutil.rb', line 8 def log(log_type,, is_base_info = true) if is_base_info puts "[#{Time.now.strftime("%Y/%m/%d %H:%M:%S")}][#{$$}][#{log_type.to_s}] #{}" else puts "[#{log_type.to_s}] #{}" end end |
#warn(message) ⇒ Object
31 32 33 |
# File 'lib/skutil.rb', line 31 def warn() log(:WARN,) end |