-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Improve logging #792
Conversation
Current coverage is 100% (diff: 100%)@@ 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
|
return record | ||
|
||
|
||
def create_logger(template, stream_level='DEBUG', debug_file=None): |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 😄
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
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? |
Removed the template info from the log records. Please have a look and let me know if you're happy to merge this. Thanks 🙇 |
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)) |
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single quotes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't
😿
I think double quotes are better than escaping the single quote.
👍 on this in general, just noticed a few consistency cleanups. |
|
Thanks a ton @michaeljoseph! 😂 🍪 |
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, acookiecutter
logger with one or two handlers:StreamHandler
logging onDEBUG
orINFO
based on--verbose
FileHandler
logging always onDEBUG
, 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 forDEBUG
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 thecookiecutter
logger.