Skip to content

Commit 6ff21c9

Browse files
authored
feat: better logging (#124)
* fix logging module name (use utils.py) * slightly better initialization function
1 parent 27eebb7 commit 6ff21c9

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

python/hooks/post_gen_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
Path("src/{{ cookiecutter.project_slug }}/models.py").unlink()
2121

2222
if (not {{ cookiecutter.add_fastapi }}) and (not {{ cookiecutter.add_cli }}):
23-
Path("./src/{{ cookiecutter.project_slug }}/logging.py").unlink()
23+
Path("./src/{{ cookiecutter.project_slug }}/utils.py").unlink()
2424
Path("src/{{ cookiecutter.project_slug }}/config.py").unlink()

python/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/logging.py

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Configure useful utilities."""
2+
3+
import logging
4+
from logging.handlers import RotatingFileHandler
5+
6+
7+
def initialize_logs(log_level: int = logging.INFO) -> None:
8+
"""Configure logging.
9+
10+
:param log_level: app log level to set
11+
"""
12+
root = logging.getLogger()
13+
if root.handlers:
14+
return
15+
16+
root.setLevel(log_level)
17+
formatter = logging.Formatter(
18+
"[%(asctime)s] - %(name)s - %(levelname)s : %(message)s"
19+
)
20+
fh = RotatingFileHandler(f"{__package__}.log", maxBytes=5_000_000, backupCount=3)
21+
fh.setFormatter(formatter)
22+
root.addHandler(fh)

0 commit comments

Comments
 (0)