Sha256: dc2e33d6f40b621742bef0e959d6d7c229725c684eb7a5132cc8c370246776a5
Contents?: true
Size: 1.75 KB
Versions: 4
Compression:
Stored size: 1.75 KB
Contents
require 'active_support/core_ext/hash/indifferent_access' module SentinelApi class Notifier class << self def warn(*args) log('WARN', args) end def info(*args) log('INFO', args) end def error(*args) log('ERROR', args) end private_class_method def log(level = nil, args) level ||= configuration.level project_name ||= configuration.project_name message, info, tags = extract_arguments(args) SentinelApi::Client.send_to_server({ level: level, message: message, info: info, tags: tags, project_name: project_name }) end def extract_arguments(args) message = nil exception = nil tags = nil if args.count == 1 && args[0].is_a?(Hash) result = args[0].with_indifferent_access return [result[:message], result[:info], result[:tags]] elsif args.count == 1 && args[0].is_a?(Exception) return [args[0].message, prepare_info(args[0]), []] else args.each do |arg| if arg.is_a?(String) message = 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) tags = arg tags = nil if tags.empty? end end end [message, prepare_info(exception), tags] end def prepare_info(exception) "#{exception.class}: #{exception.message}, \n#{exception.backtrace.join("\n")}" rescue "#{exception.class}: #{exception.message}" end def configuration SentinelApi.configuration end end end end
Version data entries
4 entries across 4 versions & 1 rubygems