{"action":"created","comment":{"url":"https://api.github.com/repos/bundler/gemstash/pulls/comments/40611775","id":40611775,"diff_hunk":"@@ -0,0 +1,85 @@\n+require \"logger\"\n+\n+module Gemstash\n+  #:nodoc:\n+  module Logging\n+    def log\n+      Gemstash::Logging.logger\n+    end\n+\n+    def self.setup_logger(logfile)\n+      @logging_sink = LoggingSink.new(logfile)\n+    end\n+\n+    def self.logger\n+      return @logging_sink.logger if @logging_sink\n+      Logger.new($stdout)\n+    end\n+\n+    def self.raw_logger\n+      return @logging_sink.raw_logger if @logging_sink\n+      $stdout\n+    end\n+\n+    def self.reset\n+      @logging_sink.close if @logging_sink\n+      @loggingasink = nil","path":"lib/gemstash/logging.rb","position":26,"original_position":26,"commit_id":"952674102e5167dd3103d4014432e67a472bae83","original_commit_id":"952674102e5167dd3103d4014432e67a472bae83","user":{"login":"pcarranza","id":4496338,"avatar_url":"https://avatars.githubusercontent.com/u/4496338?v=3","gravatar_id":"","url":"https://api.github.com/users/pcarranza","html_url":"https://github.com/pcarranza","followers_url":"https://api.github.com/users/pcarranza/followers","following_url":"https://api.github.com/users/pcarranza/following{/other_user}","gists_url":"https://api.github.com/users/pcarranza/gists{/gist_id}","starred_url":"https://api.github.com/users/pcarranza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcarranza/subscriptions","organizations_url":"https://api.github.com/users/pcarranza/orgs","repos_url":"https://api.github.com/users/pcarranza/repos","events_url":"https://api.github.com/users/pcarranza/events{/privacy}","received_events_url":"https://api.github.com/users/pcarranza/received_events","type":"User","site_admin":false},"body":"Opps, right","created_at":"2015-09-28T22:05:54Z","updated_at":"2015-09-28T22:05:54Z","html_url":"https://github.com/bundler/gemstash/pull/10#discussion_r40611775","pull_request_url":"https://api.github.com/repos/bundler/gemstash/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/comments/40611775"},"html":{"href":"https://github.com/bundler/gemstash/pull/10#discussion_r40611775"},"pull_request":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/bundler/gemstash/pulls/10","id":46210559,"html_url":"https://github.com/bundler/gemstash/pull/10","diff_url":"https://github.com/bundler/gemstash/pull/10.diff","patch_url":"https://github.com/bundler/gemstash/pull/10.patch","issue_url":"https://api.github.com/repos/bundler/gemstash/issues/10","number":10,"state":"open","locked":false,"title":"Logging all the things to a file","user":{"login":"pcarranza","id":4496338,"avatar_url":"https://avatars.githubusercontent.com/u/4496338?v=3","gravatar_id":"","url":"https://api.github.com/users/pcarranza","html_url":"https://github.com/pcarranza","followers_url":"https://api.github.com/users/pcarranza/followers","following_url":"https://api.github.com/users/pcarranza/following{/other_user}","gists_url":"https://api.github.com/users/pcarranza/gists{/gist_id}","starred_url":"https://api.github.com/users/pcarranza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcarranza/subscriptions","organizations_url":"https://api.github.com/users/pcarranza/orgs","repos_url":"https://api.github.com/users/pcarranza/repos","events_url":"https://api.github.com/users/pcarranza/events{/privacy}","received_events_url":"https://api.github.com/users/pcarranza/received_events","type":"User","site_admin":false},"body":"Logging works as expected, all the layers are writing in the same file.\r\n\r\nThis was tricky, puma is expecting to work with $stdout and $stderr to log \"events\", something where it can \"write\" to.\r\n\r\nOn the other hand, rack is also expecting to have something to what is can \"puts\" to, again $stdout/$stderr.\r\n\r\nEvery place I looked for this, whoever was speaking was saying that the way to go is just to $stdout.reopen(\"file\"), this is ok-ish, but this does not provide any easy way to rotate the log.\r\n\r\nAfter investigating how the stdlib Logger works, I realized that the object that handles the rotation of the log is Logger::LogDevice, so the way to go was to just monkey patch Logger to obtains the LogDevice, which is almost an IO, and monkey patch that other one just to provide those 2 final methods that it is looking for: puts and sync=\r\n\r\nWith this, the rotation will still happen inside the same object, so we are still using the stdlib Logger.\r\n\r\nThere is some room to improvement as depending on the source the format of the log line changes, but for now I think this is good enough","created_at":"2015-09-28T21:29:20Z","updated_at":"2015-09-28T22:05:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d6df691b2f992187c2fff08ff1cd239a907557b0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bundler/gemstash/pulls/10/commits","review_comments_url":"https://api.github.com/repos/bundler/gemstash/pulls/10/comments","review_comment_url":"https://api.github.com/repos/bundler/gemstash/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bundler/gemstash/issues/10/comments","statuses_url":"https://api.github.com/repos/bundler/gemstash/statuses/952674102e5167dd3103d4014432e67a472bae83","head":{"label":"bundler:logging","ref":"logging","sha":"952674102e5167dd3103d4014432e67a472bae83","user":{"login":"bundler","id":1137638,"avatar_url":"https://avatars.githubusercontent.com/u/1137638?v=3","gravatar_id":"","url":"https://api.github.com/users/bundler","html_url":"https://github.com/bundler","followers_url":"https://api.github.com/users/bundler/followers","following_url":"https://api.github.com/users/bundler/following{/other_user}","gists_url":"https://api.github.com/users/bundler/gists{/gist_id}","starred_url":"https://api.github.com/users/bundler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bundler/subscriptions","organizations_url":"https://api.github.com/users/bundler/orgs","repos_url":"https://api.github.com/users/bundler/repos","events_url":"https://api.github.com/users/bundler/events{/privacy}","received_events_url":"https://api.github.com/users/bundler/received_events","type":"Organization","site_admin":false},"repo":{"id":42746109,"name":"gemstash","full_name":"bundler/gemstash","owner":{"login":"bundler","id":1137638,"avatar_url":"https://avatars.githubusercontent.com/u/1137638?v=3","gravatar_id":"","url":"https://api.github.com/users/bundler","html_url":"https://github.com/bundler","followers_url":"https://api.github.com/users/bundler/followers","following_url":"https://api.github.com/users/bundler/following{/other_user}","gists_url":"https://api.github.com/users/bundler/gists{/gist_id}","starred_url":"https://api.github.com/users/bundler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bundler/subscriptions","organizations_url":"https://api.github.com/users/bundler/orgs","repos_url":"https://api.github.com/users/bundler/repos","events_url":"https://api.github.com/users/bundler/events{/privacy}","received_events_url":"https://api.github.com/users/bundler/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bundler/gemstash","description":null,"fork":false,"url":"https://api.github.com/repos/bundler/gemstash","forks_url":"https://api.github.com/repos/bundler/gemstash/forks","keys_url":"https://api.github.com/repos/bundler/gemstash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bundler/gemstash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bundler/gemstash/teams","hooks_url":"https://api.github.com/repos/bundler/gemstash/hooks","issue_events_url":"https://api.github.com/repos/bundler/gemstash/issues/events{/number}","events_url":"https://api.github.com/repos/bundler/gemstash/events","assignees_url":"https://api.github.com/repos/bundler/gemstash/assignees{/user}","branches_url":"https://api.github.com/repos/bundler/gemstash/branches{/branch}","tags_url":"https://api.github.com/repos/bundler/gemstash/tags","blobs_url":"https://api.github.com/repos/bundler/gemstash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bundler/gemstash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bundler/gemstash/git/refs{/sha}","trees_url":"https://api.github.com/repos/bundler/gemstash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bundler/gemstash/statuses/{sha}","languages_url":"https://api.github.com/repos/bundler/gemstash/languages","stargazers_url":"https://api.github.com/repos/bundler/gemstash/stargazers","contributors_url":"https://api.github.com/repos/bundler/gemstash/contributors","subscribers_url":"https://api.github.com/repos/bundler/gemstash/subscribers","subscription_url":"https://api.github.com/repos/bundler/gemstash/subscription","commits_url":"https://api.github.com/repos/bundler/gemstash/commits{/sha}","git_commits_url":"https://api.github.com/repos/bundler/gemstash/git/commits{/sha}","comments_url":"https://api.github.com/repos/bundler/gemstash/comments{/number}","issue_comment_url":"https://api.github.com/repos/bundler/gemstash/issues/comments{/number}","contents_url":"https://api.github.com/repos/bundler/gemstash/contents/{+path}","compare_url":"https://api.github.com/repos/bundler/gemstash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bundler/gemstash/merges","archive_url":"https://api.github.com/repos/bundler/gemstash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bundler/gemstash/downloads","issues_url":"https://api.github.com/repos/bundler/gemstash/issues{/number}","pulls_url":"https://api.github.com/repos/bundler/gemstash/pulls{/number}","milestones_url":"https://api.github.com/repos/bundler/gemstash/milestones{/number}","notifications_url":"https://api.github.com/repos/bundler/gemstash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bundler/gemstash/labels{/name}","releases_url":"https://api.github.com/repos/bundler/gemstash/releases{/id}","created_at":"2015-09-18T20:41:41Z","updated_at":"2015-09-27T22:56:37Z","pushed_at":"2015-09-28T21:29:20Z","git_url":"git://github.com/bundler/gemstash.git","ssh_url":"git@github.com:bundler/gemstash.git","clone_url":"https://github.com/bundler/gemstash.git","svn_url":"https://github.com/bundler/gemstash","homepage":null,"size":248,"stargazers_count":16,"watchers_count":16,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":16,"default_branch":"master"}},"base":{"label":"bundler:master","ref":"master","sha":"81a288cc23fca43ee5eefc29b1e41b092aef163d","user":{"login":"bundler","id":1137638,"avatar_url":"https://avatars.githubusercontent.com/u/1137638?v=3","gravatar_id":"","url":"https://api.github.com/users/bundler","html_url":"https://github.com/bundler","followers_url":"https://api.github.com/users/bundler/followers","following_url":"https://api.github.com/users/bundler/following{/other_user}","gists_url":"https://api.github.com/users/bundler/gists{/gist_id}","starred_url":"https://api.github.com/users/bundler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bundler/subscriptions","organizations_url":"https://api.github.com/users/bundler/orgs","repos_url":"https://api.github.com/users/bundler/repos","events_url":"https://api.github.com/users/bundler/events{/privacy}","received_events_url":"https://api.github.com/users/bundler/received_events","type":"Organization","site_admin":false},"repo":{"id":42746109,"name":"gemstash","full_name":"bundler/gemstash","owner":{"login":"bundler","id":1137638,"avatar_url":"https://avatars.githubusercontent.com/u/1137638?v=3","gravatar_id":"","url":"https://api.github.com/users/bundler","html_url":"https://github.com/bundler","followers_url":"https://api.github.com/users/bundler/followers","following_url":"https://api.github.com/users/bundler/following{/other_user}","gists_url":"https://api.github.com/users/bundler/gists{/gist_id}","starred_url":"https://api.github.com/users/bundler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bundler/subscriptions","organizations_url":"https://api.github.com/users/bundler/orgs","repos_url":"https://api.github.com/users/bundler/repos","events_url":"https://api.github.com/users/bundler/events{/privacy}","received_events_url":"https://api.github.com/users/bundler/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bundler/gemstash","description":null,"fork":false,"url":"https://api.github.com/repos/bundler/gemstash","forks_url":"https://api.github.com/repos/bundler/gemstash/forks","keys_url":"https://api.github.com/repos/bundler/gemstash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bundler/gemstash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bundler/gemstash/teams","hooks_url":"https://api.github.com/repos/bundler/gemstash/hooks","issue_events_url":"https://api.github.com/repos/bundler/gemstash/issues/events{/number}","events_url":"https://api.github.com/repos/bundler/gemstash/events","assignees_url":"https://api.github.com/repos/bundler/gemstash/assignees{/user}","branches_url":"https://api.github.com/repos/bundler/gemstash/branches{/branch}","tags_url":"https://api.github.com/repos/bundler/gemstash/tags","blobs_url":"https://api.github.com/repos/bundler/gemstash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bundler/gemstash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bundler/gemstash/git/refs{/sha}","trees_url":"https://api.github.com/repos/bundler/gemstash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bundler/gemstash/statuses/{sha}","languages_url":"https://api.github.com/repos/bundler/gemstash/languages","stargazers_url":"https://api.github.com/repos/bundler/gemstash/stargazers","contributors_url":"https://api.github.com/repos/bundler/gemstash/contributors","subscribers_url":"https://api.github.com/repos/bundler/gemstash/subscribers","subscription_url":"https://api.github.com/repos/bundler/gemstash/subscription","commits_url":"https://api.github.com/repos/bundler/gemstash/commits{/sha}","git_commits_url":"https://api.github.com/repos/bundler/gemstash/git/commits{/sha}","comments_url":"https://api.github.com/repos/bundler/gemstash/comments{/number}","issue_comment_url":"https://api.github.com/repos/bundler/gemstash/issues/comments{/number}","contents_url":"https://api.github.com/repos/bundler/gemstash/contents/{+path}","compare_url":"https://api.github.com/repos/bundler/gemstash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bundler/gemstash/merges","archive_url":"https://api.github.com/repos/bundler/gemstash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bundler/gemstash/downloads","issues_url":"https://api.github.com/repos/bundler/gemstash/issues{/number}","pulls_url":"https://api.github.com/repos/bundler/gemstash/pulls{/number}","milestones_url":"https://api.github.com/repos/bundler/gemstash/milestones{/number}","notifications_url":"https://api.github.com/repos/bundler/gemstash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bundler/gemstash/labels{/name}","releases_url":"https://api.github.com/repos/bundler/gemstash/releases{/id}","created_at":"2015-09-18T20:41:41Z","updated_at":"2015-09-27T22:56:37Z","pushed_at":"2015-09-28T21:29:20Z","git_url":"git://github.com/bundler/gemstash.git","ssh_url":"git@github.com:bundler/gemstash.git","clone_url":"https://github.com/bundler/gemstash.git","svn_url":"https://github.com/bundler/gemstash","homepage":null,"size":248,"stargazers_count":16,"watchers_count":16,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/10"},"html":{"href":"https://github.com/bundler/gemstash/pull/10"},"issue":{"href":"https://api.github.com/repos/bundler/gemstash/issues/10"},"comments":{"href":"https://api.github.com/repos/bundler/gemstash/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/bundler/gemstash/statuses/952674102e5167dd3103d4014432e67a472bae83"}}}}