Module: Log

Defined in:
lib/tracer_client/log.rb

Constant Summary collapse

SEVERITIES =

error - ошибки crit - исключения emerg - неперехваченные исключения

%i(debug info notice warn error crit alert emerg)
FACILITIES =
%i(request lib auth user product order line_item delivery odkl email direct_mail page exception)
ROBOT_UA_FRAGMENTS =
/AhrefsBot|bingbot|DotBot|Googlebot|Mail.RU_Bot|MJ12bot|msnbot|SputnikBot|updown_tester|Web-Monitoring|WebMasterAid|YaDirectFetcher|Yahoo! Slurp|YandexBot/

Class Method Summary collapse

Class Method Details

.debug(subject = '', tags = '', data = {}) ⇒ Object

Можно вызывать в сокращённой форме: Log.debug(‘Сообщение’) Log.debug(2, b: 5) Log.debug(any_object)



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tracer_client/log.rb', line 33

def self.debug(subject = '', tags = '', data = {})
  if Hash === subject
    # передан только хэш с данными
    message(:debug, subject.inspect[0...40], '', subject, caller)
  elsif String === subject
    # передан только subject
    message(:debug, subject, tags, data, caller)
  else
    # переданы некие другие данные
    message(:debug, subject.inspect[0...40], '', {debug: subject}, caller)
  end
end

.end_requestObject



23
24
25
26
# File 'lib/tracer_client/log.rb', line 23

def self.end_request
  Thread.current[:request_tags] = nil
  Tracer::Client.end_request
end

.exception(exception, subject, tags = '', data = {}) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/tracer_client/log.rb', line 60

def self.exception(exception, subject, tags = '', data = {})
  if Rails.env.development?
    raise exception
  else
    exception_message(exception, :crit, subject, tags, data, exception.backtrace)
    exception
  end
end

.exception_with_alert(exception, subject, tags = '', data = {}) ⇒ Object



70
71
72
# File 'lib/tracer_client/log.rb', line 70

def self.exception_with_alert(exception, subject, tags = '', data = {})
  exception(exception, subject, tags, data.merge(with_alert: true))
end

.on_raise(exception, backtrace) ⇒ Object



75
76
77
78
79
# File 'lib/tracer_client/log.rb', line 75

def self.on_raise(exception, backtrace)
  if exception.with_log?
    exception_message(exception, :warn, '', 'raise', {with_alert: exception.with_alert?}, backtrace)
  end
end

.start_request(current_user, request, params, session, do_log_request) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/tracer_client/log.rb', line 15

def self.start_request(current_user, request, params, session, do_log_request)
  Tracer::Client.start_request(current_user, request, params, session)

  info('HTTP запрос', 'http_request') if do_log_request

  Thread.current[:request_tags] = %w(robot) if request.headers['User-Agent'] =~ ROBOT_UA_FRAGMENTS
end

.unhandled(exception) ⇒ Object



82
83
84
85
86
# File 'lib/tracer_client/log.rb', line 82

def self.unhandled(exception)
  if exception.with_log? && !exception.logged?
    exception_message(exception, :emerg, '', 'unhandled', {with_alert: exception.with_alert?}, exception.backtrace)
  end
end