From 9cf4cc75f0d1d194ba0abcea93dea8e25f271602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AD=D0=B4=D1=83=D0=B0=D1=80=D0=B4?= Date: Mon, 6 Jul 2026 16:30:21 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BE=D0=BA=D1=80=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=D0=B2=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE?= =?UTF-8?q?=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 3a80f8c..4bf0df6 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,24 @@ import logging import sys -logging.basicConfig( - level=logging.INFO, - format='%(asctime)s %(name)s:%(lineno)d %(levelname)s %(message)s', - handlers=[ - logging.FileHandler('app.log', encoding='utf-8'), - logging.StreamHandler(sys.stdout) - ] -) + +def configure_logging(level: int = logging.INFO): + """Настраивает короткий консольный лог и подробный файловый лог.""" + file_handler = logging.FileHandler('app.log', encoding='utf-8') + file_handler.setFormatter( + logging.Formatter('%(asctime)s %(name)s:%(lineno)d %(levelname)s %(message)s') + ) + file_handler.setLevel(level) + + console_handler = logging.StreamHandler(sys.stdout) + console_handler.setFormatter(logging.Formatter('%(message)s')) + console_handler.setLevel(level) + + logging.basicConfig( + level=level, + handlers=[file_handler, console_handler], + force=True, + ) from api.clockify import ClockifyAPI # noqa: E402 @@ -22,10 +32,11 @@ from utils import check_envs, db_update, get_start_end_dates # noqa: E402 def main(): """Запускает CLI-сценарий переноса трудочасов из Clockify в Redmine.""" args = arg_parser.parse_args() + log_level = logging.DEBUG if args.debug else logging.INFO + configure_logging(log_level) if is_debug := args.debug: config.MODE = "debug" - logging.getLogger().setLevel(logging.DEBUG) if is_dry_run := args.dry_run: config.MODE = "debug"