Class: Sentinel::Notifier
- Inherits:
-
Object
- Object
- Sentinel::Notifier
- Defined in:
- lib/sentinel/notifier.rb
Class Method Summary collapse
- .configuration ⇒ Object
- .error(*args) ⇒ Object
- .extract_arguments(args) ⇒ Object
- .info(*args) ⇒ Object
- .log(level = nil, args) ⇒ Object
- .prepare_info(exception) ⇒ Object
- .warn(*args) ⇒ Object
Class Method Details
.configuration ⇒ Object
61 62 63 |
# File 'lib/sentinel/notifier.rb', line 61 def configuration Sentinel.configuration end |
.error(*args) ⇒ Object
15 16 17 |
# File 'lib/sentinel/notifier.rb', line 15 def error(*args) log('ERROR', args) end |
.extract_arguments(args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sentinel/notifier.rb', line 28 def extract_arguments(args) = nil exception = nil = nil if args.count == 1 && args[0].is_a?(Hash) result = args[0].with_indifferent_access return [result[:message], result[:info], result[:tags]] else args.each do |arg| if arg.is_a?(String) = arg elsif arg.is_a?(Exception) exception = arg elsif RUBY_PLATFORM == 'java' && arg.is_a?(java.lang.Exception) exception = arg elsif arg.is_a?(Array) = arg = nil if .empty? end end end [, prepare_info(exception), ] end |
.info(*args) ⇒ Object
11 12 13 |
# File 'lib/sentinel/notifier.rb', line 11 def info(*args) log('INFO', args) end |
.log(level = nil, args) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/sentinel/notifier.rb', line 21 def log(level = nil, args) level ||= configuration.level , info, = extract_arguments(args) Sentinel::ApiClient.send_to_server({ level: level, message: , info: info, tags: }) end |
.prepare_info(exception) ⇒ Object
54 55 56 57 58 |
# File 'lib/sentinel/notifier.rb', line 54 def prepare_info(exception) "#{exception.class}: #{exception.}, \n#{exception.backtrace.join("\n")}" rescue "#{exception.class}: #{exception.}" end |
.warn(*args) ⇒ Object
7 8 9 |
# File 'lib/sentinel/notifier.rb', line 7 def warn(*args) log('WARN', args) end |