Class: HTTParty::Logger::ApacheFormatter
- Inherits:
-
Object
- Object
- HTTParty::Logger::ApacheFormatter
- Defined in:
- lib/httparty/logger/apache_formatter.rb
Overview
:nodoc:
Constant Summary collapse
- TAG_NAME =
HTTParty.name
Instance Attribute Summary collapse
-
#current_time ⇒ Object
Returns the value of attribute current_time.
-
#level ⇒ Object
Returns the value of attribute level.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #format(request, response) ⇒ Object
-
#initialize(logger, level) ⇒ ApacheFormatter
constructor
A new instance of ApacheFormatter.
Constructor Details
#initialize(logger, level) ⇒ ApacheFormatter
Returns a new instance of ApacheFormatter.
8 9 10 11 |
# File 'lib/httparty/logger/apache_formatter.rb', line 8 def initialize(logger, level) @logger = logger @level = level.to_sym end |
Instance Attribute Details
#current_time ⇒ Object
Returns the value of attribute current_time.
6 7 8 |
# File 'lib/httparty/logger/apache_formatter.rb', line 6 def current_time @current_time end |
#level ⇒ Object
Returns the value of attribute level.
6 7 8 |
# File 'lib/httparty/logger/apache_formatter.rb', line 6 def level @level end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/httparty/logger/apache_formatter.rb', line 6 def logger @logger end |
Instance Method Details
#format(request, response) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/httparty/logger/apache_formatter.rb', line 13 def format(request, response) current_time = Time.now.strftime("%Y-%m-%d %H:%M:%S %z") http_method = request.http_method.name.split("::").last.upcase path = request.path.to_s content_length = response.respond_to?(:headers) ? response.headers['Content-Length'] : response['Content-Length'] @logger.send @level, "[#{TAG_NAME}] [#{current_time}] #{response.code} \"#{http_method} #{path}\" #{content_length || '-'} " end |