Browse Source

Strategická: Neumím s logging

master
David Klement 2 years ago
parent
commit
11281447cb
  1. 9
      klient/client.py
  2. 4
      klient/play.py

9
klient/client.py

@ -5,7 +5,12 @@ from typing import Optional, Tuple
TIME_BEFORE_RETRY = 2.0 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]: 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 # retry later if there was an error
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
logger.warning("Request error: {e}") logger.warning(f"Request error: {e}")
return None, TIME_BEFORE_RETRY return None, TIME_BEFORE_RETRY
if not r.ok: if not r.ok:
logger.warning(f"Server error: {r.status_code} {r.reason}") logger.warning(f"Server error: {r.status_code} {r.reason}")

4
klient/play.py

@ -2,7 +2,7 @@
import argparse import argparse
import time import time
from typing import Callable, Iterable, List, Optional, Tuple 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() parser = argparse.ArgumentParser()
@ -141,7 +141,7 @@ def parse_world(world: dict) -> List[List[Field]]:
def main(args: argparse.Namespace): def main(args: argparse.Namespace):
min_round = 0 min_round = 0
logger.setLevel(args.log_level) set_log_level(args.log_level)
while True: while True:
state, wait_time = get_state(min_round, args) state, wait_time = get_state(min_round, args)

Loading…
Cancel
Save