arsduo/koala — pull request #177 by KentonWhite (2012-03-29 14:52:48+00:00)
Title: Issue 140 - Implement Logger for Koala::Utils

Hi There,

I implemented a simple logger for Koala::Utils. It is based on the standard ruby logger.

By default uses the standard ruby logger set to a level of ERROR and printing to STDOUT

Usage:

Koala::Utils.debug "message"
Koala::Utils.info "message"
Koala::Utils.warn "message"
Koala::Utils.error "message"
Koala::Utils.fatal "message"

To set the logger level:

Koala::Utils.level = Logger::DEBUG
Koala::Utils.level = Logger::INFO
Koala::Utils.level = Logger::WARN
Koala::Utils.level = Logger::ERROR
Koala::Utils.level = Logger::FATAL

To send logs to a file:

Koala::Utils.logger = Logger.new("path/to/log")

Note: Doing this will set the level to DEBUG

A custom logger can be used as long as it responds to the methods #debug, #info, #warn, #error, #fatal, #level

To use a custom logger:

Koala::Utils.logger = MyCustomLogger.new

As per the request, I also added the logger to HttpService#make_request to log the verb, url, and params. Here are more details:

Prints to the current logger the following information for each request made to facebook:

VERB: path params: {hash of params}

Example output:

D, [2012-03-29T10:25:10.767226 #4837] DEBUG -- : GET: /me/feed params: {"access_token"=>"REDACTED", "limit"=>"25", "until"=>"1296947395"}

Logging is disabled by default.

To enable logging add Koala::Utils.level = Logger::DEBUG

I included this request logging as a separate commit in case you wish to have to have the logger but not to include logging of the request to Facebook.

I tried to implement as best I could the interface you suggested in the issue. If you have any suggestions for improving the interface, please let me know and I'll be happy to make the modifications.