diff --git a/clashroyalebuildabot/bot/example/custom_bot.py b/clashroyalebuildabot/bot/example/custom_bot.py index 2e26975..3ff1ec8 100644 --- a/clashroyalebuildabot/bot/example/custom_bot.py +++ b/clashroyalebuildabot/bot/example/custom_bot.py @@ -1,9 +1,11 @@ import random import subprocess import time +import os +import yaml +import sys from loguru import logger - from clashroyalebuildabot.bot import Bot from clashroyalebuildabot.bot.bot import Action from clashroyalebuildabot.bot.example.custom_action import CustomAction @@ -23,6 +25,16 @@ class CustomBot(Bot): ] def __init__(self, cards=None, debug=False): + config_path = os.path.join(os.path.dirname(__file__), "..", "..", "config.yaml") + with open(config_path, encoding="utf-8") as file: + config = yaml.safe_load(file) + + log_level = config.get("bot", {}).get("log_level", "INFO").upper() + + logger.remove() + logger.add(sys.stdout, level=log_level) + logger.add(os.path.join(os.path.dirname(__file__), "..", "bot.log"), rotation="500 MB", level=log_level) + if cards is None: cards = self.PRESET_DECK if set(cards) != set(self.PRESET_DECK): diff --git a/clashroyalebuildabot/config.yaml b/clashroyalebuildabot/config.yaml index a7c5b48..949e0c1 100644 --- a/clashroyalebuildabot/config.yaml +++ b/clashroyalebuildabot/config.yaml @@ -1,3 +1,9 @@ +bot: + # The logging level for the bot. + # Use "DEBUG" for detailed debugging information, "INFO" for general information, + # "WARNING" for warning messages, "ERROR" for error messages, and "CRITICAL" for critical issues. + log_level: "INFO" + adb: # The IP address of your device or emulator. # Use 127.0.0.1 for a local emulator. If you're connecting to a physical device, diff --git a/clashroyalebuildabot/emulator.py b/clashroyalebuildabot/emulator.py index a727a50..9d2c4c1 100644 --- a/clashroyalebuildabot/emulator.py +++ b/clashroyalebuildabot/emulator.py @@ -1,14 +1,10 @@ import os - from adb_shell.adb_device import AdbDeviceTcp from loguru import logger from PIL import Image import yaml - -from clashroyalebuildabot.constants import SCREENSHOT_HEIGHT -from clashroyalebuildabot.constants import SCREENSHOT_WIDTH -from clashroyalebuildabot.constants import SRC_DIR - +import sys +from clashroyalebuildabot.constants import SCREENSHOT_HEIGHT, SCREENSHOT_WIDTH, SRC_DIR class Emulator: def __init__(self): @@ -16,6 +12,11 @@ def __init__(self): with open(config_path, encoding="utf-8") as file: config = yaml.safe_load(file) + log_level = config.get("bot", {}).get("log_level", "INFO").upper() + logger.remove() + logger.add(sys.stdout, level=log_level) + logger.add(os.path.join(SRC_DIR, "bot.log"), rotation="500 MB", level=log_level) + adb_config = config["adb"] device_ip = adb_config["ip"] device_port = adb_config["port"] diff --git a/main.py b/main.py index 7c7dec9..dd99e28 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import sys import threading import time +import yaml from loguru import logger from clashroyalebuildabot.bot.example.custom_bot import CustomBot from clashroyalebuildabot.constants import DEBUG_DIR @@ -25,8 +26,18 @@ def main(): bot.run() if __name__ == "__main__": + config_path = os.path.join(os.path.dirname(__file__), "clashroyalebuildabot/config.yaml") + with open(config_path, encoding="utf-8") as file: + config = yaml.safe_load(file) + + log_level = config.get("bot", {}).get("log_level", "INFO").upper() + + logger.remove() + logger.add(sys.stdout, level=log_level) + logger.add(os.path.join(DEBUG_DIR, "bot.log"), rotation="500 MB", level=log_level) + + # Update-Prüfung und Hauptprogramm starten Updater().check_for_update() - logger.add(os.path.join(DEBUG_DIR, "bot.log"), rotation="500 MB") title_thread = threading.Thread(target=update_terminal_title, daemon=True) title_thread.start() main()