Skip to content

Commit

Permalink
Merge pull request #3 from launchdarkly/pk/logging-improvements
Browse files Browse the repository at this point in the history
made logging messages safer and included [LDClient] tag so people know w...
  • Loading branch information
pkaeding committed Nov 21, 2014
2 parents 9e2afac + d8412d3 commit c3f66f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/ldclient-rb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Config
#
# @return [type] [description]
def initialize(opts = {})
@base_uri = opts[:base_uri] || Config.default_base_uri
@base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
@capacity = opts[:capacity] || Config.default_capacity
@logger = opts[:logger] || Config.default_logger
@store = opts[:store] || Config.default_store
Expand Down
14 changes: 7 additions & 7 deletions lib/ldclient-rb/ldclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def initialize(api_key, config = Config.default)
req.body = events.to_json
end
if res.status != 200
@config.logger.error("Unexpected status code while processing events: " + res.status)
@config.logger.error("[LDClient] Unexpected status code while processing events: #{res.status}")
end
end

Expand Down Expand Up @@ -95,7 +95,7 @@ def get_flag?(key, user, default=false)
add_event({:kind => 'feature', :key => key, :user => user, :value => value})
return value
rescue StandardError => error
@config.logger.error("Unhandled exception in get_flag: " + error.message)
@config.logger.error("[LDClient] Unhandled exception in get_flag: #{error.message}")
default
end
end
Expand All @@ -105,7 +105,7 @@ def add_event(event)
event[:creationDate] = (Time.now.to_f * 1000).to_i
@queue.push(event)
else
@config.logger.warn("Exceeded event queue capacity. Increase capacity to avoid dropping events.")
@config.logger.warn("[LDClient] Exceeded event queue capacity. Increase capacity to avoid dropping events.")
end
end

Expand All @@ -124,7 +124,7 @@ def send_event(event_name, user, data)
def get_flag_int(key, user, default)

unless user
@config.logger.error("Must specify user")
@config.logger.error("[LDClient] Must specify user")
return default
end

Expand All @@ -135,17 +135,17 @@ def get_flag_int(key, user, default)
end

if res.status == 401
@config.logger.error("Invalid API key")
@config.logger.error("[LDClient] Invalid API key")
return default
end

if res.status == 404
@config.logger.error("Unknown feature key: " + key)
@config.logger.error("[LDClient] Unknown feature key: #{key}")
return default
end

if res.status != 200
@config.logger.error("Unexpected status code " + res.status)
@config.logger.error("[LDClient] Unexpected status code #{res.status}")
return default
end

Expand Down

0 comments on commit c3f66f3

Please sign in to comment.