{"action":"created","comment":{"url":"https://api.github.com/repos/audreyr/cookiecutter/pulls/comments/72936382","id":72936382,"diff_hunk":"@@ -0,0 +1,65 @@\n+# -*- coding: utf-8 -*-\n+\n+import logging\n+import sys\n+\n+LOG_LEVELS = {\n+    'DEBUG': logging.DEBUG,\n+    'INFO': logging.INFO,\n+    'WARNING': logging.WARNING,\n+    'ERROR': logging.ERROR,\n+    'CRITICAL': logging.CRITICAL,\n+}\n+\n+LOG_FORMATS = {\n+    'DEBUG': u'%(levelname)s [%(template)s] %(name)s: %(message)s',\n+    'INFO': u'%(levelname)s: %(message)s',\n+}\n+\n+\n+class ContextFilter(logging.Filter):\n+    \"\"\"Logging filter that holds the name of the used template.\"\"\"\n+\n+    def __init__(self, template):\n+        super(ContextFilter, self).__init__()\n+        self.template = template\n+\n+    def filter(self, record):\n+        \"\"\"Add 'template' as extra information on a logging record.\"\"\"\n+        record.template = self.template\n+        return record\n+\n+\n+def create_logger(template, stream_level='DEBUG', debug_file=None):","path":"cookiecutter/log.py","position":null,"original_position":33,"commit_id":"b99c67504cb23c5ff2ab99d964f1cd18756a7b16","original_commit_id":"228a4d40deeb78adf1aed66cfcbd6250292149c2","user":{"login":"hackebrot","id":6024445,"avatar_url":"https://avatars.githubusercontent.com/u/6024445?v=3","gravatar_id":"","url":"https://api.github.com/users/hackebrot","html_url":"https://github.com/hackebrot","followers_url":"https://api.github.com/users/hackebrot/followers","following_url":"https://api.github.com/users/hackebrot/following{/other_user}","gists_url":"https://api.github.com/users/hackebrot/gists{/gist_id}","starred_url":"https://api.github.com/users/hackebrot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hackebrot/subscriptions","organizations_url":"https://api.github.com/users/hackebrot/orgs","repos_url":"https://api.github.com/users/hackebrot/repos","events_url":"https://api.github.com/users/hackebrot/events{/privacy}","received_events_url":"https://api.github.com/users/hackebrot/received_events","type":"User","site_admin":false},"body":"I agree! Updated to ``configure_logger``. Thanks 😄 ","created_at":"2016-08-01T07:54:54Z","updated_at":"2016-08-01T07:54:54Z","html_url":"https://github.com/audreyr/cookiecutter/pull/792#discussion_r72936382","pull_request_url":"https://api.github.com/repos/audreyr/cookiecutter/pulls/792","_links":{"self":{"href":"https://api.github.com/repos/audreyr/cookiecutter/pulls/comments/72936382"},"html":{"href":"https://github.com/audreyr/cookiecutter/pull/792#discussion_r72936382"},"pull_request":{"href":"https://api.github.com/repos/audreyr/cookiecutter/pulls/792"}}},"pull_request":{"url":"https://api.github.com/repos/audreyr/cookiecutter/pulls/792","id":79498256,"html_url":"https://github.com/audreyr/cookiecutter/pull/792","diff_url":"https://github.com/audreyr/cookiecutter/pull/792.diff","patch_url":"https://github.com/audreyr/cookiecutter/pull/792.patch","issue_url":"https://api.github.com/repos/audreyr/cookiecutter/issues/792","number":792,"state":"open","locked":false,"title":"Improve logging","user":{"login":"hackebrot","id":6024445,"avatar_url":"https://avatars.githubusercontent.com/u/6024445?v=3","gravatar_id":"","url":"https://api.github.com/users/hackebrot","html_url":"https://github.com/hackebrot","followers_url":"https://api.github.com/users/hackebrot/followers","following_url":"https://api.github.com/users/hackebrot/following{/other_user}","gists_url":"https://api.github.com/users/hackebrot/gists{/gist_id}","starred_url":"https://api.github.com/users/hackebrot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hackebrot/subscriptions","organizations_url":"https://api.github.com/users/hackebrot/orgs","repos_url":"https://api.github.com/users/hackebrot/repos","events_url":"https://api.github.com/users/hackebrot/events{/privacy}","received_events_url":"https://api.github.com/users/hackebrot/received_events","type":"User","site_admin":false},"body":"This PR adds sophisticated logging to cookiecutter! 😃 \r\n\r\n``$ cookiecutter --debug-file generate-plugin.log cookiecutter-pytest-plugin``\r\n\r\nRather than using ``logging.basicConfig`` to set up the root logger and a handler, a ``cookiecutter`` logger with one or two handlers:\r\n\r\n- ``StreamHandler`` logging on ``DEBUG`` or ``INFO`` based on ``--verbose``\r\n- ``FileHandler`` logging **always** on ``DEBUG``, but only added if a file is provided via ``--debug-file=foo.log``\r\n\r\nThe idea is to allow users to optionally output information about files/directories generated w/o polluting ``stdout``. The format for ``DEBUG`` logging now also mentions the template as specified by the user to the log messages, which will come in handy especially when using the debug file .\r\n\r\nResolves #633 \r\n\r\n---\r\n\r\nWhile working on [cibopath](https://github.com/hackebrot/cibopath) I noticed side effects of using ``logging.basicConfig`` which luckily never caused problems in Cookiecutter. This PR solves this problem by explicitly setting up the ``cookiecutter`` logger.\r\n\r\n```python\r\n# -*- coding: utf-8 -*-\r\n\r\nimport logging\r\n\r\n# This causes problems when run before basicConfig\r\n# Comment out to see different stdout logging\r\n# or to ``logging.getLogger('foo').info('Before basicConfig')``\r\nlogging.info('Before basicConfig')\r\n\r\nlogging.basicConfig(\r\n    format=u'%(levelname)s: %(message)s',\r\n    level=logging.DEBUG\r\n)\r\n\r\nlogging.info('After basicConfig')\r\nlogging.debug('After basicConfig')\r\n```\r\n\r\n","created_at":"2016-07-31T22:37:42Z","updated_at":"2016-08-01T07:54:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2d9b8cfc5946f6310af5594e7c6a29279c7c677e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/audreyr/cookiecutter/pulls/792/commits","review_comments_url":"https://api.github.com/repos/audreyr/cookiecutter/pulls/792/comments","review_comment_url":"https://api.github.com/repos/audreyr/cookiecutter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/audreyr/cookiecutter/issues/792/comments","statuses_url":"https://api.github.com/repos/audreyr/cookiecutter/statuses/b99c67504cb23c5ff2ab99d964f1cd18756a7b16","head":{"label":"hackebrot:improve-logging","ref":"improve-logging","sha":"b99c67504cb23c5ff2ab99d964f1cd18756a7b16","user":{"login":"hackebrot","id":6024445,"avatar_url":"https://avatars.githubusercontent.com/u/6024445?v=3","gravatar_id":"","url":"https://api.github.com/users/hackebrot","html_url":"https://github.com/hackebrot","followers_url":"https://api.github.com/users/hackebrot/followers","following_url":"https://api.github.com/users/hackebrot/following{/other_user}","gists_url":"https://api.github.com/users/hackebrot/gists{/gist_id}","starred_url":"https://api.github.com/users/hackebrot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hackebrot/subscriptions","organizations_url":"https://api.github.com/users/hackebrot/orgs","repos_url":"https://api.github.com/users/hackebrot/repos","events_url":"https://api.github.com/users/hackebrot/events{/privacy}","received_events_url":"https://api.github.com/users/hackebrot/received_events","type":"User","site_admin":false},"repo":{"id":19483501,"name":"cookiecutter","full_name":"hackebrot/cookiecutter","owner":{"login":"hackebrot","id":6024445,"avatar_url":"https://avatars.githubusercontent.com/u/6024445?v=3","gravatar_id":"","url":"https://api.github.com/users/hackebrot","html_url":"https://github.com/hackebrot","followers_url":"https://api.github.com/users/hackebrot/followers","following_url":"https://api.github.com/users/hackebrot/following{/other_user}","gists_url":"https://api.github.com/users/hackebrot/gists{/gist_id}","starred_url":"https://api.github.com/users/hackebrot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hackebrot/subscriptions","organizations_url":"https://api.github.com/users/hackebrot/orgs","repos_url":"https://api.github.com/users/hackebrot/repos","events_url":"https://api.github.com/users/hackebrot/events{/privacy}","received_events_url":"https://api.github.com/users/hackebrot/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hackebrot/cookiecutter","description":"A command-line utility that creates projects from cookiecutters (project templates). E.g. Python package projects, jQuery plugin projects.","fork":true,"url":"https://api.github.com/repos/hackebrot/cookiecutter","forks_url":"https://api.github.com/repos/hackebrot/cookiecutter/forks","keys_url":"https://api.github.com/repos/hackebrot/cookiecutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hackebrot/cookiecutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hackebrot/cookiecutter/teams","hooks_url":"https://api.github.com/repos/hackebrot/cookiecutter/hooks","issue_events_url":"https://api.github.com/repos/hackebrot/cookiecutter/issues/events{/number}","events_url":"https://api.github.com/repos/hackebrot/cookiecutter/events","assignees_url":"https://api.github.com/repos/hackebrot/cookiecutter/assignees{/user}","branches_url":"https://api.github.com/repos/hackebrot/cookiecutter/branches{/branch}","tags_url":"https://api.github.com/repos/hackebrot/cookiecutter/tags","blobs_url":"https://api.github.com/repos/hackebrot/cookiecutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hackebrot/cookiecutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hackebrot/cookiecutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/hackebrot/cookiecutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hackebrot/cookiecutter/statuses/{sha}","languages_url":"https://api.github.com/repos/hackebrot/cookiecutter/languages","stargazers_url":"https://api.github.com/repos/hackebrot/cookiecutter/stargazers","contributors_url":"https://api.github.com/repos/hackebrot/cookiecutter/contributors","subscribers_url":"https://api.github.com/repos/hackebrot/cookiecutter/subscribers","subscription_url":"https://api.github.com/repos/hackebrot/cookiecutter/subscription","commits_url":"https://api.github.com/repos/hackebrot/cookiecutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/hackebrot/cookiecutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/hackebrot/cookiecutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/hackebrot/cookiecutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/hackebrot/cookiecutter/contents/{+path}","compare_url":"https://api.github.com/repos/hackebrot/cookiecutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hackebrot/cookiecutter/merges","archive_url":"https://api.github.com/repos/hackebrot/cookiecutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hackebrot/cookiecutter/downloads","issues_url":"https://api.github.com/repos/hackebrot/cookiecutter/issues{/number}","pulls_url":"https://api.github.com/repos/hackebrot/cookiecutter/pulls{/number}","milestones_url":"https://api.github.com/repos/hackebrot/cookiecutter/milestones{/number}","notifications_url":"https://api.github.com/repos/hackebrot/cookiecutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hackebrot/cookiecutter/labels{/name}","releases_url":"https://api.github.com/repos/hackebrot/cookiecutter/releases{/id}","deployments_url":"https://api.github.com/repos/hackebrot/cookiecutter/deployments","created_at":"2014-05-06T06:28:14Z","updated_at":"2016-05-25T13:48:27Z","pushed_at":"2016-08-01T07:54:11Z","git_url":"git://github.com/hackebrot/cookiecutter.git","ssh_url":"git@github.com:hackebrot/cookiecutter.git","clone_url":"https://github.com/hackebrot/cookiecutter.git","svn_url":"https://github.com/hackebrot/cookiecutter","homepage":"","size":1745,"stargazers_count":2,"watchers_count":2,"language":"Python","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":2,"default_branch":"master"}},"base":{"label":"audreyr:master","ref":"master","sha":"0301bf6637a0a0ffd34238b64ff1ba3e1919dc66","user":{"login":"audreyr","id":74739,"avatar_url":"https://avatars.githubusercontent.com/u/74739?v=3","gravatar_id":"","url":"https://api.github.com/users/audreyr","html_url":"https://github.com/audreyr","followers_url":"https://api.github.com/users/audreyr/followers","following_url":"https://api.github.com/users/audreyr/following{/other_user}","gists_url":"https://api.github.com/users/audreyr/gists{/gist_id}","starred_url":"https://api.github.com/users/audreyr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/audreyr/subscriptions","organizations_url":"https://api.github.com/users/audreyr/orgs","repos_url":"https://api.github.com/users/audreyr/repos","events_url":"https://api.github.com/users/audreyr/events{/privacy}","received_events_url":"https://api.github.com/users/audreyr/received_events","type":"User","site_admin":false},"repo":{"id":11407242,"name":"cookiecutter","full_name":"audreyr/cookiecutter","owner":{"login":"audreyr","id":74739,"avatar_url":"https://avatars.githubusercontent.com/u/74739?v=3","gravatar_id":"","url":"https://api.github.com/users/audreyr","html_url":"https://github.com/audreyr","followers_url":"https://api.github.com/users/audreyr/followers","following_url":"https://api.github.com/users/audreyr/following{/other_user}","gists_url":"https://api.github.com/users/audreyr/gists{/gist_id}","starred_url":"https://api.github.com/users/audreyr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/audreyr/subscriptions","organizations_url":"https://api.github.com/users/audreyr/orgs","repos_url":"https://api.github.com/users/audreyr/repos","events_url":"https://api.github.com/users/audreyr/events{/privacy}","received_events_url":"https://api.github.com/users/audreyr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/audreyr/cookiecutter","description":"A command-line utility that creates projects from cookiecutters (project templates). E.g. Python package projects, jQuery plugin projects.","fork":false,"url":"https://api.github.com/repos/audreyr/cookiecutter","forks_url":"https://api.github.com/repos/audreyr/cookiecutter/forks","keys_url":"https://api.github.com/repos/audreyr/cookiecutter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/audreyr/cookiecutter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/audreyr/cookiecutter/teams","hooks_url":"https://api.github.com/repos/audreyr/cookiecutter/hooks","issue_events_url":"https://api.github.com/repos/audreyr/cookiecutter/issues/events{/number}","events_url":"https://api.github.com/repos/audreyr/cookiecutter/events","assignees_url":"https://api.github.com/repos/audreyr/cookiecutter/assignees{/user}","branches_url":"https://api.github.com/repos/audreyr/cookiecutter/branches{/branch}","tags_url":"https://api.github.com/repos/audreyr/cookiecutter/tags","blobs_url":"https://api.github.com/repos/audreyr/cookiecutter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/audreyr/cookiecutter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/audreyr/cookiecutter/git/refs{/sha}","trees_url":"https://api.github.com/repos/audreyr/cookiecutter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/audreyr/cookiecutter/statuses/{sha}","languages_url":"https://api.github.com/repos/audreyr/cookiecutter/languages","stargazers_url":"https://api.github.com/repos/audreyr/cookiecutter/stargazers","contributors_url":"https://api.github.com/repos/audreyr/cookiecutter/contributors","subscribers_url":"https://api.github.com/repos/audreyr/cookiecutter/subscribers","subscription_url":"https://api.github.com/repos/audreyr/cookiecutter/subscription","commits_url":"https://api.github.com/repos/audreyr/cookiecutter/commits{/sha}","git_commits_url":"https://api.github.com/repos/audreyr/cookiecutter/git/commits{/sha}","comments_url":"https://api.github.com/repos/audreyr/cookiecutter/comments{/number}","issue_comment_url":"https://api.github.com/repos/audreyr/cookiecutter/issues/comments{/number}","contents_url":"https://api.github.com/repos/audreyr/cookiecutter/contents/{+path}","compare_url":"https://api.github.com/repos/audreyr/cookiecutter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/audreyr/cookiecutter/merges","archive_url":"https://api.github.com/repos/audreyr/cookiecutter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/audreyr/cookiecutter/downloads","issues_url":"https://api.github.com/repos/audreyr/cookiecutter/issues{/number}","pulls_url":"https://api.github.com/repos/audreyr/cookiecutter/pulls{/number}","milestones_url":"https://api.github.com/repos/audreyr/cookiecutter/milestones{/number}","notifications_url":"https://api.github.com/repos/audreyr/cookiecutter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/audreyr/cookiecutter/labels{/name}","releases_url":"https://api.github.com/repos/audreyr/cookiecutter/releases{/id}","deployments_url":"https://api.github.com/repos/audreyr/cookiecutter/deployments","created_at":"2013-07-14T18:31:22Z","updated_at":"2016-08-01T05:37:26Z","pushed_at":"2016-08-01T07:54:12Z","git_url":"git://github.com/audreyr/cookiecutter.git","ssh_url":"git@github.com:audreyr/cookiecutter.git","clone_url":"https://github.com/audreyr/cookiecutter.git","svn_url":"https://github.com/audreyr/cookiecutter","homepage":"","size":2894,"stargazers_count":3643,"watchers_count":3643,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":439,"mirror_url":null,"open_issues_count":105,"forks":439,"open_issues":105,"watchers":3643,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/audreyr/cookiecutter/pulls/792"},"html":{"href":"https://github.com/audreyr/cookiecutter/pull/792"},"issue":{"href":"https://api.github.com/repos/audreyr/cookiecutter/issues/792"},"comments":{"href":"https://api.github.com/repos/audreyr/cookiecutter/issues/792/comments"},"review_comments":{"href":"https://api.github.com/repos/audreyr/cookiecutter/pulls/792/comments"},"review_comment":{"href":"https://api.github.com/repos/audreyr/cookiecutter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/audreyr/cookiecutter/pulls/792/commits"},"statuses":{"href":"https://api.github.com/repos/audreyr/cookiecutter/statuses/b99c67504cb23c5ff2ab99d964f1cd18756a7b16"}}}}
{"actor":{"display_login":"hackebrot"}}