{"action":"created","comment":{"url":"https://api.github.com/repos/omise/omise-ruby/pulls/comments/53572139","id":53572139,"diff_hunk":"@@ -0,0 +1,53 @@\n+module Omise\n+  class Logger\n+    LABEL = \"[Omise]\".freeze\n+\n+    attr_reader :log\n+\n+    def initialize(log = nil)\n+      @log = log\n+    end\n+\n+    def log_request(request, args)\n+      return unless log\n+      return unless can_log_request?(request)\n+\n+      message =  with_line_break { \"#{LABEL} Request: #{args[:method].to_s.upcase} #{args[:url]}\" }\n+      message << with_line_break { format_headers(request) }\n+      message << with_line_break { format_payload(args[:payload]) } if args[:payload]\n+\n+      log.info(message)\n+    end\n+\n+    def log_response(response)\n+      return unless log\n+\n+      net_http = response.net_http_res\n+\n+      message =  with_line_break { \"#{LABEL} Response: HTTP/#{net_http.http_version} #{net_http.code} #{net_http.message}\" }\n+      message << with_line_break { format_headers(net_http) }\n+      message << with_line_break { response.body }","path":"lib/omise/logger.rb","position":29,"original_position":29,"commit_id":"3f2ea0a5c777288083dde7b7a7cf919f2c1a8773","original_commit_id":"9b5e91a2ed7b8bf6a46e6d2c7e72b2a460db6f75","user":{"login":"robinclart","id":149619,"avatar_url":"https://avatars.githubusercontent.com/u/149619?v=3","gravatar_id":"","url":"https://api.github.com/users/robinclart","html_url":"https://github.com/robinclart","followers_url":"https://api.github.com/users/robinclart/followers","following_url":"https://api.github.com/users/robinclart/following{/other_user}","gists_url":"https://api.github.com/users/robinclart/gists{/gist_id}","starred_url":"https://api.github.com/users/robinclart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robinclart/subscriptions","organizations_url":"https://api.github.com/users/robinclart/orgs","repos_url":"https://api.github.com/users/robinclart/repos","events_url":"https://api.github.com/users/robinclart/events{/privacy}","received_events_url":"https://api.github.com/users/robinclart/received_events","type":"User","site_admin":false},"body":"We could use a StringIO here instead of using the with_line_break. And even possibly make a small wrapper like this:\r\n\r\n```ruby\r\nrequire \"stringio\"\r\n\r\nclass LogMessage\r\n  def initialize\r\n    @message = StringIO.new\r\n  end\r\n\r\n  def puts(str)\r\n    @message.puts(str)\r\n  end\r\n\r\n  def to_s\r\n    @message.rewind\r\n    @message.read\r\n  end\r\nend\r\n\r\nmessage = LogMessage.new\r\nmessage.puts \"hello\"\r\nmessage.puts \"world\"\r\nmessage.to_s # => \"hello\\nworld\\n\"\r\n```\r\n\r\nAnd I think `log.info(message)` should call `to_s` or `inspect` somewhere down the line and everything should continue to work as expected. Otherwise just call `to_s` here directly.","created_at":"2016-02-21T19:54:08Z","updated_at":"2016-02-21T19:54:08Z","html_url":"https://github.com/omise/omise-ruby/pull/11#discussion_r53572139","pull_request_url":"https://api.github.com/repos/omise/omise-ruby/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/omise/omise-ruby/pulls/comments/53572139"},"html":{"href":"https://github.com/omise/omise-ruby/pull/11#discussion_r53572139"},"pull_request":{"href":"https://api.github.com/repos/omise/omise-ruby/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/omise/omise-ruby/pulls/11","id":59283727,"html_url":"https://github.com/omise/omise-ruby/pull/11","diff_url":"https://github.com/omise/omise-ruby/pull/11.diff","patch_url":"https://github.com/omise/omise-ruby/pull/11.patch","issue_url":"https://api.github.com/repos/omise/omise-ruby/issues/11","number":11,"state":"open","locked":false,"title":"Support to log HTTP requests.","user":{"login":"prodis","id":79254,"avatar_url":"https://avatars.githubusercontent.com/u/79254?v=3","gravatar_id":"","url":"https://api.github.com/users/prodis","html_url":"https://github.com/prodis","followers_url":"https://api.github.com/users/prodis/followers","following_url":"https://api.github.com/users/prodis/following{/other_user}","gists_url":"https://api.github.com/users/prodis/gists{/gist_id}","starred_url":"https://api.github.com/users/prodis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prodis/subscriptions","organizations_url":"https://api.github.com/users/prodis/orgs","repos_url":"https://api.github.com/users/prodis/repos","events_url":"https://api.github.com/users/prodis/events{/privacy}","received_events_url":"https://api.github.com/users/prodis/received_events","type":"User","site_admin":false},"body":"Delegates HTTP requests log to RestClient.\r\n\r\nTo enable log you can set `Omise.logger` with a Ruby logger. All HTTP requests will be logged.\r\n\r\nTo disable log, just configure `Omise.logger` to `nil`. Default is disabled.\r\n\r\nAn example configuring Rails logger:\r\n\r\n```ruby\r\nOmise.logger = Rails.logger\r\n```","created_at":"2016-02-14T01:31:58Z","updated_at":"2016-02-21T19:54:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"31225a1326398e0b75e513639d03a3902c72a92d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/omise/omise-ruby/pulls/11/commits","review_comments_url":"https://api.github.com/repos/omise/omise-ruby/pulls/11/comments","review_comment_url":"https://api.github.com/repos/omise/omise-ruby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/omise/omise-ruby/issues/11/comments","statuses_url":"https://api.github.com/repos/omise/omise-ruby/statuses/3f2ea0a5c777288083dde7b7a7cf919f2c1a8773","head":{"label":"prodis:master","ref":"master","sha":"3f2ea0a5c777288083dde7b7a7cf919f2c1a8773","user":{"login":"prodis","id":79254,"avatar_url":"https://avatars.githubusercontent.com/u/79254?v=3","gravatar_id":"","url":"https://api.github.com/users/prodis","html_url":"https://github.com/prodis","followers_url":"https://api.github.com/users/prodis/followers","following_url":"https://api.github.com/users/prodis/following{/other_user}","gists_url":"https://api.github.com/users/prodis/gists{/gist_id}","starred_url":"https://api.github.com/users/prodis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prodis/subscriptions","organizations_url":"https://api.github.com/users/prodis/orgs","repos_url":"https://api.github.com/users/prodis/repos","events_url":"https://api.github.com/users/prodis/events{/privacy}","received_events_url":"https://api.github.com/users/prodis/received_events","type":"User","site_admin":false},"repo":{"id":51367844,"name":"omise-ruby","full_name":"prodis/omise-ruby","owner":{"login":"prodis","id":79254,"avatar_url":"https://avatars.githubusercontent.com/u/79254?v=3","gravatar_id":"","url":"https://api.github.com/users/prodis","html_url":"https://github.com/prodis","followers_url":"https://api.github.com/users/prodis/followers","following_url":"https://api.github.com/users/prodis/following{/other_user}","gists_url":"https://api.github.com/users/prodis/gists{/gist_id}","starred_url":"https://api.github.com/users/prodis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prodis/subscriptions","organizations_url":"https://api.github.com/users/prodis/orgs","repos_url":"https://api.github.com/users/prodis/repos","events_url":"https://api.github.com/users/prodis/events{/privacy}","received_events_url":"https://api.github.com/users/prodis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/prodis/omise-ruby","description":"Omise Ruby Library","fork":true,"url":"https://api.github.com/repos/prodis/omise-ruby","forks_url":"https://api.github.com/repos/prodis/omise-ruby/forks","keys_url":"https://api.github.com/repos/prodis/omise-ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prodis/omise-ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prodis/omise-ruby/teams","hooks_url":"https://api.github.com/repos/prodis/omise-ruby/hooks","issue_events_url":"https://api.github.com/repos/prodis/omise-ruby/issues/events{/number}","events_url":"https://api.github.com/repos/prodis/omise-ruby/events","assignees_url":"https://api.github.com/repos/prodis/omise-ruby/assignees{/user}","branches_url":"https://api.github.com/repos/prodis/omise-ruby/branches{/branch}","tags_url":"https://api.github.com/repos/prodis/omise-ruby/tags","blobs_url":"https://api.github.com/repos/prodis/omise-ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prodis/omise-ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prodis/omise-ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/prodis/omise-ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prodis/omise-ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/prodis/omise-ruby/languages","stargazers_url":"https://api.github.com/repos/prodis/omise-ruby/stargazers","contributors_url":"https://api.github.com/repos/prodis/omise-ruby/contributors","subscribers_url":"https://api.github.com/repos/prodis/omise-ruby/subscribers","subscription_url":"https://api.github.com/repos/prodis/omise-ruby/subscription","commits_url":"https://api.github.com/repos/prodis/omise-ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/prodis/omise-ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/prodis/omise-ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/prodis/omise-ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/prodis/omise-ruby/contents/{+path}","compare_url":"https://api.github.com/repos/prodis/omise-ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prodis/omise-ruby/merges","archive_url":"https://api.github.com/repos/prodis/omise-ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prodis/omise-ruby/downloads","issues_url":"https://api.github.com/repos/prodis/omise-ruby/issues{/number}","pulls_url":"https://api.github.com/repos/prodis/omise-ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/prodis/omise-ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/prodis/omise-ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prodis/omise-ruby/labels{/name}","releases_url":"https://api.github.com/repos/prodis/omise-ruby/releases{/id}","deployments_url":"https://api.github.com/repos/prodis/omise-ruby/deployments","created_at":"2016-02-09T13:19:45Z","updated_at":"2016-02-09T13:19:46Z","pushed_at":"2016-02-21T19:50:53Z","git_url":"git://github.com/prodis/omise-ruby.git","ssh_url":"git@github.com:prodis/omise-ruby.git","clone_url":"https://github.com/prodis/omise-ruby.git","svn_url":"https://github.com/prodis/omise-ruby","homepage":"https://www.omise.co/","size":83,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"omise:master","ref":"master","sha":"311e8a5691a4237348fb5e3f7f2ac63e89140247","user":{"login":"omise","id":4662729,"avatar_url":"https://avatars.githubusercontent.com/u/4662729?v=3","gravatar_id":"","url":"https://api.github.com/users/omise","html_url":"https://github.com/omise","followers_url":"https://api.github.com/users/omise/followers","following_url":"https://api.github.com/users/omise/following{/other_user}","gists_url":"https://api.github.com/users/omise/gists{/gist_id}","starred_url":"https://api.github.com/users/omise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omise/subscriptions","organizations_url":"https://api.github.com/users/omise/orgs","repos_url":"https://api.github.com/users/omise/repos","events_url":"https://api.github.com/users/omise/events{/privacy}","received_events_url":"https://api.github.com/users/omise/received_events","type":"Organization","site_admin":false},"repo":{"id":23648427,"name":"omise-ruby","full_name":"omise/omise-ruby","owner":{"login":"omise","id":4662729,"avatar_url":"https://avatars.githubusercontent.com/u/4662729?v=3","gravatar_id":"","url":"https://api.github.com/users/omise","html_url":"https://github.com/omise","followers_url":"https://api.github.com/users/omise/followers","following_url":"https://api.github.com/users/omise/following{/other_user}","gists_url":"https://api.github.com/users/omise/gists{/gist_id}","starred_url":"https://api.github.com/users/omise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omise/subscriptions","organizations_url":"https://api.github.com/users/omise/orgs","repos_url":"https://api.github.com/users/omise/repos","events_url":"https://api.github.com/users/omise/events{/privacy}","received_events_url":"https://api.github.com/users/omise/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/omise/omise-ruby","description":"Omise Ruby Library","fork":false,"url":"https://api.github.com/repos/omise/omise-ruby","forks_url":"https://api.github.com/repos/omise/omise-ruby/forks","keys_url":"https://api.github.com/repos/omise/omise-ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/omise/omise-ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/omise/omise-ruby/teams","hooks_url":"https://api.github.com/repos/omise/omise-ruby/hooks","issue_events_url":"https://api.github.com/repos/omise/omise-ruby/issues/events{/number}","events_url":"https://api.github.com/repos/omise/omise-ruby/events","assignees_url":"https://api.github.com/repos/omise/omise-ruby/assignees{/user}","branches_url":"https://api.github.com/repos/omise/omise-ruby/branches{/branch}","tags_url":"https://api.github.com/repos/omise/omise-ruby/tags","blobs_url":"https://api.github.com/repos/omise/omise-ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/omise/omise-ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/omise/omise-ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/omise/omise-ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/omise/omise-ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/omise/omise-ruby/languages","stargazers_url":"https://api.github.com/repos/omise/omise-ruby/stargazers","contributors_url":"https://api.github.com/repos/omise/omise-ruby/contributors","subscribers_url":"https://api.github.com/repos/omise/omise-ruby/subscribers","subscription_url":"https://api.github.com/repos/omise/omise-ruby/subscription","commits_url":"https://api.github.com/repos/omise/omise-ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/omise/omise-ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/omise/omise-ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/omise/omise-ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/omise/omise-ruby/contents/{+path}","compare_url":"https://api.github.com/repos/omise/omise-ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/omise/omise-ruby/merges","archive_url":"https://api.github.com/repos/omise/omise-ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/omise/omise-ruby/downloads","issues_url":"https://api.github.com/repos/omise/omise-ruby/issues{/number}","pulls_url":"https://api.github.com/repos/omise/omise-ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/omise/omise-ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/omise/omise-ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/omise/omise-ruby/labels{/name}","releases_url":"https://api.github.com/repos/omise/omise-ruby/releases{/id}","deployments_url":"https://api.github.com/repos/omise/omise-ruby/deployments","created_at":"2014-09-04T04:29:43Z","updated_at":"2016-02-06T12:42:47Z","pushed_at":"2016-02-21T19:50:54Z","git_url":"git://github.com/omise/omise-ruby.git","ssh_url":"git@github.com:omise/omise-ruby.git","clone_url":"https://github.com/omise/omise-ruby.git","svn_url":"https://github.com/omise/omise-ruby","homepage":"https://www.omise.co/","size":81,"stargazers_count":14,"watchers_count":14,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":3,"forks":5,"open_issues":3,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/omise/omise-ruby/pulls/11"},"html":{"href":"https://github.com/omise/omise-ruby/pull/11"},"issue":{"href":"https://api.github.com/repos/omise/omise-ruby/issues/11"},"comments":{"href":"https://api.github.com/repos/omise/omise-ruby/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/omise/omise-ruby/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/omise/omise-ruby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/omise/omise-ruby/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/omise/omise-ruby/statuses/3f2ea0a5c777288083dde7b7a7cf919f2c1a8773"}}}}