From 608a8548fb5e2f09e4d3951e2957077b1ea76388 Mon Sep 17 00:00:00 2001 From: Adam Saudagar Date: Thu, 3 Feb 2022 04:09:39 +0530 Subject: [PATCH] set logging level to info by default, and switch to debug when turned on from debug options changed almost all of print statement to debug logs --- fishy/__main__.py | 10 +++++----- fishy/engine/common/window.py | 4 ++-- fishy/engine/fullautofisher/engine.py | 14 +++++++------- fishy/gui/log_config.py | 8 +++++--- fishy/helper/hotkey/hotkey_process.py | 4 +++- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/fishy/__main__.py b/fishy/__main__.py index 1d4939e..fed5662 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -36,7 +36,7 @@ def initialize(window_to_hide): if new_session is None: logging.error("Couldn't create a session, some features might not work") - print(f"created session {new_session}") + logging.debug(f"created session {new_session}") try: is_admin = os.getuid() == 0 @@ -54,6 +54,8 @@ def initialize(window_to_hide): def main(): + print("launching please wait...") + config.init() if not gui.check_eula(): return @@ -67,12 +69,10 @@ def main(): finish_splash() update_dialog.check_update(gui_window) - print("launching please wait...") - info_logger = ["comtypes", "PIL"] for i in info_logger: - pil_logger = logging.getLogger(i) - pil_logger.setLevel(logging.INFO) + _logger = logging.getLogger(i) + _logger.setLevel(logging.INFO) window_to_hide = win32gui.GetForegroundWindow() diff --git a/fishy/engine/common/window.py b/fishy/engine/common/window.py index 215baf3..e451e1c 100644 --- a/fishy/engine/common/window.py +++ b/fishy/engine/common/window.py @@ -47,9 +47,9 @@ class WindowClient: return None if not window_server.screen_ready(): - print("waiting for screen...") + logging.debug("waiting for screen...") helper.wait_until(window_server.screen_ready) - print("screen ready, continuing...") + logging.debug("screen ready, continuing...") temp_img = WindowServer.Screen diff --git a/fishy/engine/fullautofisher/engine.py b/fishy/engine/fullautofisher/engine.py index f0bbcd4..ec2dd6f 100644 --- a/fishy/engine/fullautofisher/engine.py +++ b/fishy/engine/fullautofisher/engine.py @@ -122,13 +122,13 @@ class FullAuto(IEngine): if not current: return False - print(f"Moving from {(current[0], current[1])} to {target}") + logging.debug(f"Moving from {(current[0], current[1])} to {target}") move_vec = target[0] - current[0], target[1] - current[1] dist = math.sqrt(move_vec[0] ** 2 + move_vec[1] ** 2) - print(f"distance: {dist}") + logging.debug(f"distance: {dist}") if dist < 5e-05: - print("distance very small skipping") + logging.debug("distance very small skipping") return True target_angle = math.degrees(math.atan2(-move_vec[1], move_vec[0])) + 90 @@ -138,11 +138,11 @@ class FullAuto(IEngine): return False walking_time = dist / self.calibrator.move_factor - print(f"walking for {walking_time}") + logging.debug(f"walking for {walking_time}") kb.press('w') time.sleep(walking_time) kb.release('w') - print("done") + logging.debug("done") # todo: maybe check if it reached the destination before returning true? return True @@ -157,7 +157,7 @@ class FullAuto(IEngine): target_angle = 360 + target_angle while target_angle > 360: target_angle -= 360 - print(f"Rotating from {from_angle} to {target_angle}") + logging.debug(f"Rotating from {from_angle} to {target_angle}") angle_diff = target_angle - from_angle @@ -166,7 +166,7 @@ class FullAuto(IEngine): rotate_times = int(angle_diff / self.calibrator.rot_factor) * -1 - print(f"rotate_times: {rotate_times}") + logging.debug(f"rotate_times: {rotate_times}") for _ in range(abs(rotate_times)): mse.move(sign(rotate_times) * FullAuto.rotate_by * -1, 0) diff --git a/fishy/gui/log_config.py b/fishy/gui/log_config.py index e05c755..5696c87 100644 --- a/fishy/gui/log_config.py +++ b/fishy/gui/log_config.py @@ -2,6 +2,8 @@ import logging import typing from logging import StreamHandler, Formatter +from fishy.helper.config import config + if typing.TYPE_CHECKING: from . import GUI @@ -12,9 +14,9 @@ class GUIStreamHandler(StreamHandler): self.gui = gui def emit(self, record): - # todo implement verbose/debug option to show more info - # formatter = Formatter('%(name)s - %(levelname)s - %(message)s') - # self.setFormatter(formatter) + formatter = Formatter('%(levelname)s - %(message)s') + self.setFormatter(formatter) + self.setLevel(logging.DEBUG if config.get("debug", False) else logging.INFO) msg = self.format(record) self.gui.call_in_thread(lambda: _write_to_console(self.gui, msg)) diff --git a/fishy/helper/hotkey/hotkey_process.py b/fishy/helper/hotkey/hotkey_process.py index e82efed..f8219c7 100644 --- a/fishy/helper/hotkey/hotkey_process.py +++ b/fishy/helper/hotkey/hotkey_process.py @@ -1,3 +1,4 @@ +import logging import time from multiprocessing import Process, Queue from threading import Thread @@ -69,10 +70,11 @@ class HotKey: def start(self): self.process.start() self.event.start() + logging.debug("hotkey process started") def stop(self): self.inq.put("stop") self.outq.put("stop") self.process.join() self.event.join() - print("hotkey process ended") + logging.debug("hotkey process ended")