Browse Source

Strategická: Neumím s logging

master
David Klement 1 year 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
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}")

4
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)

Loading…
Cancel
Save