Class: InfluxDB2::LoggingHelper
- Inherits:
-
Object
- Object
- InfluxDB2::LoggingHelper
- Defined in:
- lib/influxdb2/client/utils/logging_helper.rb
Overview
Helper to easy use a logger across the library.
Instance Method Summary collapse
- #_headers(request, prefix) ⇒ Object
- #after_request(http_version, code, message, headers, payload) ⇒ Object
- #before_request(uri, method, headers, payload) ⇒ Object
-
#initialize(logger) ⇒ LoggingHelper
constructor
A new instance of LoggingHelper.
- #log(level, message) ⇒ Object
Constructor Details
#initialize(logger) ⇒ LoggingHelper
Returns a new instance of LoggingHelper.
25 26 27 |
# File 'lib/influxdb2/client/utils/logging_helper.rb', line 25 def initialize(logger) @logger = logger end |
Instance Method Details
#_headers(request, prefix) ⇒ Object
60 61 62 63 64 |
# File 'lib/influxdb2/client/utils/logging_helper.rb', line 60 def _headers(request, prefix) request.each do |k, v| log(:debug, "#{prefix} #{k}: #{k.casecmp('authorization').zero? ? '***' : v}") end end |
#after_request(http_version, code, message, headers, payload) ⇒ Object
54 55 56 57 58 |
# File 'lib/influxdb2/client/utils/logging_helper.rb', line 54 def after_request(http_version, code, , headers, payload) log(:debug, "<- HTTP/#{http_version} #{code} #{}") _headers(headers, '<-') log(:debug, "<- #{payload}") if payload end |
#before_request(uri, method, headers, payload) ⇒ Object
48 49 50 51 52 |
# File 'lib/influxdb2/client/utils/logging_helper.rb', line 48 def before_request(uri, method, headers, payload) log(:debug, "-> #{method} #{uri}") _headers(headers, '->') log(:debug, "-> #{payload}") if payload end |
#log(level, message) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/influxdb2/client/utils/logging_helper.rb', line 29 def log(level, ) return unless @logger log_level = case level when :debug then Logger::DEBUG when :warn then Logger::WARN when :error then Logger::ERROR when :fatal then Logger::FATAL else Logger::INFO end @logger.add(log_level) { } end |