Skip to content
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

Add logging example code for when create_cli==no #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ repos:
hooks:
- id: check-added-large-files
- id: check-ast
# exclude because of jinja templates
exclude: \{\{cookiecutter.project_slug\}\}/.+\.py
- id: check-merge-conflict
- id: check-yaml
# exclude because of jinja templates
exclude: \{\{cookiecutter.project_slug\}\}/.gitlab-ci.yml
- id: end-of-file-fixer
- id: mixed-line-ending
Expand Down
23 changes: 22 additions & 1 deletion {{cookiecutter.project_slug}}/notebooks/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,28 @@
"To use your module `{{ cookiecutter.module_name }}` from here, run `pip install -e .` from the root of your project directory."
{% endif %}
]
},
},{% if cookiecutter.config_file != 'none' %}
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
{% if cookiecutter.config_file == 'yaml' %}"import os\n",
{% endif %}"import logging\n",
"from {{ cookiecutter.module_name }} import util\n",
"\n",
"logger = logging.getLogger(\"{{ cookiecutter.module_name }}\")\n",
"\n",
"config = util.load_config({% if cookiecutter.config_file == 'yaml' %}os.path.join(os.path.abspath(os.pardir),\n",
" \"config\",\n",
" \"config.yml\"){% endif %})\n",
"util.logging_setup(config)\n",
"\n",
"logger.info(\"Use this setup to start logging in notebooks or to \"+\n",
" \"get the correct logging format in your {{ cookiecutter.module_name }} module\")"
]
},{% endif %}
{
"cell_type": "code",
"execution_count": null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import logging

from {{ cookiecutter.module_name }} import util

logger = logging.getLogger('{{ cookiecutter.module_name }}')


def main():
{% if cookiecutter.config_file != 'none' -%}
config = util.load_config({% if cookiecutter.config_file == 'yaml' %}'config/config.yml'{% else %}None{% endif %})
util.logging_setup(config)
{% else -%}
logging.basicConfig(level=logging.INFO)
{% endif -%}
logger.info("Looks like you're all set up. Let's get going!")
# TODO your journey starts here
print("hello :)")


if __name__ == "__main__":
Expand Down