Skip to content

Commit

Permalink
Add basic files (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanato12 authored Sep 14, 2024
1 parent 1bfd155 commit 0831b80
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# app logs
/logs
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ init:
pip install -r requirements.txt
pip install -r requirements-dev.txt

.PHONY: run
run:
python main.py

.PHONY: lint
lint:
ruff --version
Expand Down
5 changes: 5 additions & 0 deletions app/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from logging import Logger, getLogger


def get_file_path_logger(module: str) -> Logger:
return getLogger(module.replace(".", "/"))
32 changes: 31 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
print("hello.")
import logging
from logging import StreamHandler, basicConfig
from logging.handlers import TimedRotatingFileHandler
from os import makedirs

from app.logger import get_file_path_logger

LOG_DIRECTORY = "logs"

logger = get_file_path_logger(__name__)

if __name__ == "__main__":
makedirs(LOG_DIRECTORY, exist_ok=True)

basicConfig(
level=logging.INFO,
datefmt="%Y/%m/%d %H:%M:%S",
format="%(asctime)s [%(levelname)s] %(name)s:%(lineno)s %(message)s",
handlers=[
TimedRotatingFileHandler(
f"{LOG_DIRECTORY}/app.log",
when="midnight",
backupCount=30,
interval=1,
encoding="utf-8",
),
StreamHandler(),
],
)

logger.info("hello.")

0 comments on commit 0831b80

Please sign in to comment.