From 11281447cbf112d913bdac0fd74172bb33947b1b Mon Sep 17 00:00:00 2001 From: kulisak12 Date: Wed, 14 Sep 2022 15:28:25 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20Neum=C3=ADm=20s=20logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- klient/client.py | 9 +++++++-- klient/play.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/klient/client.py b/klient/client.py index 9b2b875..21410fd 100644 --- a/klient/client.py +++ b/klient/client.py @@ -5,7 +5,12 @@ from typing import Optional, Tuple TIME_BEFORE_RETRY = 2.0 -logger = logging.Logger("client") +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger("client") + + +def set_log_level(log_level: str): + logger.setLevel(log_level) def get_state(min_round: int, args) -> Tuple[Optional[dict], float]: @@ -19,7 +24,7 @@ def get_state(min_round: int, args) -> Tuple[Optional[dict], float]: }) # retry later if there was an error except requests.exceptions.RequestException as e: - logger.warning("Request error: {e}") + logger.warning(f"Request error: {e}") return None, TIME_BEFORE_RETRY if not r.ok: logger.warning(f"Server error: {r.status_code} {r.reason}") diff --git a/klient/play.py b/klient/play.py index af30dc6..7a3fc11 100755 --- a/klient/play.py +++ b/klient/play.py @@ -2,7 +2,7 @@ import argparse import time from typing import Callable, Iterable, List, Optional, Tuple -from client import get_state, send_turn, logger, TIME_BEFORE_RETRY +from client import get_state, send_turn, set_log_level, TIME_BEFORE_RETRY parser = argparse.ArgumentParser() @@ -141,7 +141,7 @@ def parse_world(world: dict) -> List[List[Field]]: def main(args: argparse.Namespace): min_round = 0 - logger.setLevel(args.log_level) + set_log_level(args.log_level) while True: state, wait_time = get_state(min_round, args)