Class: WialonApi::Logger
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- WialonApi::Logger
- Defined in:
- lib/wialon_api/logger.rb
Overview
Faraday middleware for logging requests and responses.
It's behaviour depends on the logging options in the configuration.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Logs the request if needed.
-
#initialize(app) ⇒ Logger
constructor
Creates a middleware instance.
-
#on_complete(env) ⇒ Object
Logs the response (successful or not) if needed.
Constructor Details
Instance Method Details
#call(env) ⇒ Object
Logs the request if needed.
15 16 17 18 19 20 21 22 |
# File 'lib/wialon_api/logger.rb', line 15 def call(env) if WialonApi.log_requests? @logger.debug "#{env[:method].to_s.upcase} #{env[:url]}" @logger.debug "body: #{env[:body].inspect}" unless env[:method] == :get end super end |
#on_complete(env) ⇒ Object
Logs the response (successful or not) if needed.
26 27 28 29 30 31 32 |
# File 'lib/wialon_api/logger.rb', line 26 def on_complete(env) if env[:body].respond_to?(:error) && env[:body].error? @logger.warn env[:raw_body] if WialonApi.log_errors? else @logger.debug env[:raw_body] if WialonApi.log_responses? end end |