-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from savonrb/fix_logger_nomethoderror
Fix NoMethodError when not using NTLM
- Loading branch information
Showing
2 changed files
with
51 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require "logger" | ||
|
||
module HTTPI | ||
|
||
class << self | ||
|
||
# Sets whether to log HTTP requests. | ||
attr_writer :log | ||
|
||
# Returns whether to log HTTP requests. Defaults to +true+. | ||
def log? | ||
@log != false | ||
end | ||
|
||
# Sets the logger to use. | ||
attr_writer :logger | ||
|
||
# Returns the logger. Defaults to an instance of +Logger+ writing to STDOUT. | ||
def logger | ||
@logger ||= ::Logger.new($stdout) | ||
end | ||
|
||
# Sets the log level. | ||
attr_writer :log_level | ||
|
||
# Returns the log level. Defaults to :debug. | ||
def log_level | ||
@log_level ||= DEFAULT_LOG_LEVEL | ||
end | ||
|
||
# Logs a given +message+. | ||
def log(message) | ||
logger.send(log_level, message) if log? | ||
end | ||
|
||
# Reset the default config. | ||
def reset_config! | ||
@log = nil | ||
@logger = nil | ||
@log_level = nil | ||
end | ||
|
||
protected | ||
|
||
def log_request(method, request, adapter) | ||
log("HTTPI #{method.to_s.upcase} request to #{request.url.host} (#{adapter})") | ||
end | ||
|
||
end | ||
end |