Class: HTTParty::Logger::ApacheLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/httparty/logger/apache_logger.rb

Overview

:nodoc:

Constant Summary

TAG_NAME =
HTTParty.name

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ApacheLogger) initialize(logger, level)

Returns a new instance of ApacheLogger



8
9
10
11
# File 'lib/httparty/logger/apache_logger.rb', line 8

def initialize(logger, level)
  @logger = logger
  @level  = level.to_sym
end

Instance Attribute Details

- (Object) current_time

Returns the value of attribute current_time



6
7
8
# File 'lib/httparty/logger/apache_logger.rb', line 6

def current_time
  @current_time
end

- (Object) level

Returns the value of attribute level



6
7
8
# File 'lib/httparty/logger/apache_logger.rb', line 6

def level
  @level
end

- (Object) logger

Returns the value of attribute logger



6
7
8
# File 'lib/httparty/logger/apache_logger.rb', line 6

def logger
  @logger
end

Instance Method Details

- (Object) format(request, response)



13
14
15
16
17
18
19
# File 'lib/httparty/logger/apache_logger.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['Content-Length']
  @logger.send @level, "[#{TAG_NAME}] [#{current_time}] #{response.code} \"#{http_method} #{path}\" #{content_length || "-"} "
end