Skip to content

Commit

Permalink
feat(main, io_handler): set logging level with CLI argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamhexi committed Sep 22, 2024
1 parent 170476c commit c3b46d1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
40 changes: 40 additions & 0 deletions knowledge_verificator/io_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import logging

from logging import Logger
from rich.console import Console
from rich.logging import RichHandler
from argparse import ArgumentParser


def get_argument_parser() -> ArgumentParser:
parser = ArgumentParser(
prog='knowledge_verificator',
)

parser.add_argument(
'-d',
'--debug',
action='store_true',
help=(
'Turn on debug mode, which shows all logs including those from '
'`debug` and `info` levels.'
),
)

return parser


console = Console()
logger = Logger('main_logger')

logging_handler = RichHandler(rich_tracebacks=True)

parser = get_argument_parser()
args = parser.parse_args()

logging_level = logging.WARNING
if args.debug:
logging_level = logging.DEBUG

logging_handler.setLevel(logging_level)
logger.addHandler(logging_handler)
14 changes: 0 additions & 14 deletions knowledge_verificator/logger.py

This file was deleted.

4 changes: 2 additions & 2 deletions knowledge_verificator/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Main module with CLI definition."""

from logger import logger, console
from io_handler import logger, console
from rich.text import Text

from knowledge_verificator.answer_chooser import AnswerChooser
Expand Down Expand Up @@ -37,7 +37,7 @@
)

console.print(
f'Answer the question with full sentence. {question} \n Your answer.: '
f'\nAnswer the question with full sentence. {question} \nYour answer: '
)
user_answer = input().strip()

Expand Down

0 comments on commit c3b46d1

Please sign in to comment.