8000 Improve logging by hackebrot · Pull Request #792 · cookiecutter/cookiecutter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve logging #792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 11, 2016
Merged

Improve logging #792

merged 19 commits into from
Sep 11, 2016

Conversation

hackebrot
Copy link
Member
@hackebrot hackebrot commented Jul 31, 2016

This PR adds sophisticated logging to cookiecutter! 😃

$ cookiecutter --debug-file generate-plugin.log cookiecutter-pytest-plugin

Rather than using logging.basicConfig to set up the root logger and a handler, a cookiecutter logger with one or two handlers:

  • StreamHandler logging on DEBUG or INFO based on --verbose
  • FileHandler logging always on DEBUG, but only added if a file is provided via --debug-file=foo.log

The 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 .

Resolves #633


While working on 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.

# -*- coding: utf-8 -*-

import logging

# This causes problems when run before basicConfig
# Comment out to see different stdout logging
# or to ``logging.getLogger('foo').info('Before basicConfig')``
logging.info('Before basicConfig')

logging.basicConfig(
    format=u'%(levelname)s: %(message)s',
    level=logging.DEBUG
)

logging.info('After basicConfig')
logging.debug('After basicConfig')

@hackebrot hackebrot added enhancement This issue/PR relates to a feature request. needs-review PR Only: This PR require review from other developer labels Jul 31, 2016
@codecov-io
Copy link
codecov-io commented Jul 31, 2016

Current coverage is 100% (diff: 100%)

Merging #792 into master will not change coverage

@@           master   #792   diff @@
====================================
  Files          15     16     +1   
  Lines         601    630    +29   
  Methods         0      0          
  Messages        0      0          
  Branches        0      0          
====================================
+ Hits          601    630    +29   
  Misses          0      0          
  Partials        0      0          

Sunburst

Powered by Codecov. Last update ad872a0...a42528a

return record


def create_logger(template, stream_level='DEBUG', debug_file=None):
Copy link
Contributor
@ionelmc ionelmc Aug 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be named configure_logging? I expected something totally different given the current name (like a function that just returns a half-configured logger object). Currently you're not using the return value (tests don't count).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! Updated to configure_logger. Thanks 😄

@hackebrot
Copy link
Member Author

What do you think @audreyr @michaeljoseph @pydanny? 😺

click.echo(click.get_current_context().get_help())
sys.exit(0)

template_name = os.path.basename(os.path.abspath(template))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this do the right thing for template URLs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm looks like it does. I use the same code as we do in main.py, however I didn't take into account that it's cloned first and hence refers to a directory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas? At this stage we don't really know much about the template that is being passed in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that's not correct, the code in main uses the same parameter.

(it's then used for the --replay feature)

@hackebrot
Copy link
Member Author

I've been trying to solve this issue, however I'm not entir 8000 ely happy with what I've got so far. I might as well remove the template information from the log records.

What do you think?

@hackebrot
Copy link
Member Author

Removed the template info from the log records.

Please have a look and let me know if you're happy to merge this. Thanks 🙇

@hackebrot
Copy link
Member Author

Hey @audreyr @pydanny @michaeljoseph! 👋

If you have the time, can you please review this PR? I'd like to have this merged and cut a release soon-ish.

Thanks 🙇


def find_template(repo_dir):
"""Determine which child directory of `repo_dir` is the project template.

:param repo_dir: Local directory of newly cloned repo.
:returns project_template: Relative path to project template.
""&qu 8000 ot;
logging.debug('Searching {0} for the project template.'.format(repo_dir))
logger.debug('Searching {0} for the project template.'.format(repo_dir))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rm positional index.

'Loading user config from home dir',

"DEBUG cookiecutter.foo.bar: "
"I don't know.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quotes here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

67E6

don't 😿

I think double quotes are better than escaping the single quote.

@michaeljoseph
Copy link
Contributor

👍 on this in general, just noticed a few consistency cleanups.

@michaeljoseph
Copy link
Contributor

:shipit:

@hackebrot hackebrot merged commit 2ab37b4 into cookiecutter:master Sep 11, 2016
@hackebrot
Copy link
Member Author

Thanks a ton @michaeljoseph! 😂 🍪

@hackebrot hackebrot deleted the improve-logging branch September 11, 2016 16:14
hackebrot added a commit that referenced this pull request Sep 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue/PR relates to a feature request. needs-review PR Only: This PR require review from other developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0