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
-
.debug(subject = '', tags = '', data = {}) ⇒ Object
Можно вызывать в сокращённой форме: Log.debug(‘Сообщение’) Log.debug(2, b: 5) Log.debug(any_object).
- .end_request ⇒ Object
- .exception(exception, subject, tags = '', data = {}) ⇒ Object
- .exception_with_alert(exception, subject, tags = '', data = {}) ⇒ Object
- .on_raise(exception, backtrace) ⇒ Object
- .start_request(current_user, request, params, session, do_log_request) ⇒ Object
- .unhandled(exception) ⇒ Object
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 = '', = '', data = {}) if Hash === subject # передан только хэш с данными (:debug, subject.inspect[0...40], '', subject, caller) elsif String === subject # передан только subject (:debug, subject, , data, caller) else # переданы некие другие данные (:debug, subject.inspect[0...40], '', {debug: subject}, caller) end end |
.end_request ⇒ Object
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, = '', data = {}) if Rails.env.development? raise exception else (exception, :crit, subject, , 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, = '', data = {}) exception(exception, subject, , 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, :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, :emerg, '', 'unhandled', {with_alert: exception.with_alert?}, exception.backtrace) end end |