Review and adjust the logging module levels
This commit is contained in:
1 parent
51b2da3e42
commit
76467bad65
5 files changed
+33
-24
No files matched your search
+4
-1
@@ -77,11 +77,14 @@ WATCH_INTERVAL = timedelta(seconds=59)
|
|||||||
DROPS_ENABLED_TAG = "c2542d6d-cd10-4532-919b-3d19f30a768b"
|
DROPS_ENABLED_TAG = "c2542d6d-cd10-4532-919b-3d19f30a768b"
|
||||||
WINDOW_TITLE = f"Twitch Drops Miner v{__version__} (by DevilXD)"
|
WINDOW_TITLE = f"Twitch Drops Miner v{__version__} (by DevilXD)"
|
||||||
# Logging
|
# Logging
|
||||||
FORMATTER = logging.Formatter(
|
FILE_FORMATTER = logging.Formatter(
|
||||||
"{asctime}.{msecs:03.0f}:\t{levelname:>7}:\t{message}",
|
"{asctime}.{msecs:03.0f}:\t{levelname:>7}:\t{message}",
|
||||||
style='{',
|
style='{',
|
||||||
datefmt="%Y-%m-%d %H:%M:%S",
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||||||
)
|
)
|
||||||
|
OUTPUT_FORMATTER = logging.Formatter(
|
||||||
|
"{asctime}: {levelname:>7}: {message}", style='{', datefmt="%H:%M:%S"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class State(Enum):
|
class State(Enum):
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ from translate import _
|
|||||||
from cache import ImageCache
|
from cache import ImageCache
|
||||||
from exceptions import ExitRequest
|
from exceptions import ExitRequest
|
||||||
from utils import resource_path, Game, _T
|
from utils import resource_path, Game, _T
|
||||||
from constants import SELF_PATH, FORMATTER, WS_TOPICS_LIMIT, MAX_WEBSOCKETS, WINDOW_TITLE, State
|
from constants import (
|
||||||
|
SELF_PATH, OUTPUT_FORMATTER, WS_TOPICS_LIMIT, MAX_WEBSOCKETS, WINDOW_TITLE, State
|
||||||
|
)
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
from registry import RegistryKey, ValueType
|
from registry import RegistryKey, ValueType
|
||||||
|
|
||||||
@@ -1837,8 +1839,11 @@ class GUIManager:
|
|||||||
root.minsize(width=root.winfo_reqwidth(), height=root.winfo_reqheight())
|
root.minsize(width=root.winfo_reqwidth(), height=root.winfo_reqheight())
|
||||||
# register logging handler
|
# register logging handler
|
||||||
self._handler = _TKOutputHandler(self)
|
self._handler = _TKOutputHandler(self)
|
||||||
self._handler.setFormatter(FORMATTER)
|
self._handler.setFormatter(OUTPUT_FORMATTER)
|
||||||
logging.getLogger("TwitchDrops").addHandler(self._handler)
|
logger = logging.getLogger("TwitchDrops")
|
||||||
|
logger.addHandler(self._handler)
|
||||||
|
if (logging_level := logger.getEffectiveLevel()) < logging.ERROR:
|
||||||
|
self.print(f"Logging level: {logging.getLevelName(logging_level)}")
|
||||||
# gracefully handle Windows shutdown closing the application
|
# gracefully handle Windows shutdown closing the application
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
# NOTE: this root.update() is required for the below to work - don't remove
|
# NOTE: this root.update() is required for the below to work - don't remove
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ if __name__ == "__main__":
|
|||||||
from utils import resource_path
|
from utils import resource_path
|
||||||
from version import __version__
|
from version import __version__
|
||||||
from exceptions import CaptchaRequired
|
from exceptions import CaptchaRequired
|
||||||
from constants import SELF_PATH, FORMATTER, LOG_PATH, WINDOW_TITLE
|
from constants import SELF_PATH, FILE_FORMATTER, LOG_PATH, WINDOW_TITLE
|
||||||
|
|
||||||
class Parser(argparse.ArgumentParser):
|
class Parser(argparse.ArgumentParser):
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
@@ -155,7 +155,7 @@ if __name__ == "__main__":
|
|||||||
logger.setLevel(settings.logging_level)
|
logger.setLevel(settings.logging_level)
|
||||||
if settings.log:
|
if settings.log:
|
||||||
handler = logging.FileHandler(LOG_PATH)
|
handler = logging.FileHandler(LOG_PATH)
|
||||||
handler.setFormatter(FORMATTER)
|
handler.setFormatter(FILE_FORMATTER)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
logging.getLogger("TwitchDrops.gql").setLevel(settings.debug_gql)
|
logging.getLogger("TwitchDrops.gql").setLevel(settings.debug_gql)
|
||||||
logging.getLogger("TwitchDrops.websocket").setLevel(settings.debug_ws)
|
logging.getLogger("TwitchDrops.websocket").setLevel(settings.debug_ws)
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ class _AuthState:
|
|||||||
await coro_unless_closed(login_form.wait_for_login_press())
|
await coro_unless_closed(login_form.wait_for_login_press())
|
||||||
|
|
||||||
async def _login(self) -> str:
|
async def _login(self) -> str:
|
||||||
logger.debug("Login flow started")
|
logger.info("Login flow started")
|
||||||
gui_print = self._twitch.gui.print
|
gui_print = self._twitch.gui.print
|
||||||
login_form: LoginForm = self._twitch.gui.login
|
login_form: LoginForm = self._twitch.gui.login
|
||||||
|
|
||||||
@@ -325,13 +325,13 @@ class _AuthState:
|
|||||||
# Error handling
|
# Error handling
|
||||||
if "error_code" in login_response:
|
if "error_code" in login_response:
|
||||||
error_code: int = login_response["error_code"]
|
error_code: int = login_response["error_code"]
|
||||||
logger.debug(f"Login error code: {error_code}")
|
logger.info(f"Login error code: {error_code}")
|
||||||
if error_code == 1000:
|
if error_code == 1000:
|
||||||
logger.debug("1000: CAPTCHA is required")
|
logger.info("1000: CAPTCHA is required")
|
||||||
use_chrome = True
|
use_chrome = True
|
||||||
break
|
break
|
||||||
elif error_code == 3001:
|
elif error_code == 3001:
|
||||||
logger.debug("3001: Login failed due to incorrect username or password")
|
logger.info("3001: Login failed due to incorrect username or password")
|
||||||
gui_print(_("login", "incorrect_login_pass"))
|
gui_print(_("login", "incorrect_login_pass"))
|
||||||
login_form.clear(password=True)
|
login_form.clear(password=True)
|
||||||
continue
|
continue
|
||||||
@@ -339,7 +339,7 @@ class _AuthState:
|
|||||||
3012, # Invalid authy token
|
3012, # Invalid authy token
|
||||||
3023, # Invalid email code
|
3023, # Invalid email code
|
||||||
):
|
):
|
||||||
logger.debug("3012/23: Login failed due to incorrect 2FA code")
|
logger.info("3012/23: Login failed due to incorrect 2FA code")
|
||||||
if error_code == 3023:
|
if error_code == 3023:
|
||||||
token_kind = "email"
|
token_kind = "email"
|
||||||
gui_print(_("login", "incorrect_email_code"))
|
gui_print(_("login", "incorrect_email_code"))
|
||||||
@@ -353,7 +353,7 @@ class _AuthState:
|
|||||||
3022, # Email code needed
|
3022, # Email code needed
|
||||||
):
|
):
|
||||||
# 2FA handling
|
# 2FA handling
|
||||||
logger.debug("3011/22: 2FA token required")
|
logger.info("3011/22: 2FA token required")
|
||||||
# user didn't provide a token, so ask them for it
|
# user didn't provide a token, so ask them for it
|
||||||
if error_code == 3022:
|
if error_code == 3022:
|
||||||
token_kind = "email"
|
token_kind = "email"
|
||||||
@@ -376,17 +376,17 @@ class _AuthState:
|
|||||||
# "error_description":"client blocked from this operation"
|
# "error_description":"client blocked from this operation"
|
||||||
# }
|
# }
|
||||||
gui_print(_("login", "error_code").format(error_code=error_code))
|
gui_print(_("login", "error_code").format(error_code=error_code))
|
||||||
logger.debug(str(login_response))
|
logger.info(str(login_response))
|
||||||
use_chrome = True
|
use_chrome = True
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
ext_msg = str(login_response)
|
ext_msg = str(login_response)
|
||||||
logger.debug(ext_msg)
|
logger.info(ext_msg)
|
||||||
raise LoginException(ext_msg)
|
raise LoginException(ext_msg)
|
||||||
# Success handling
|
# Success handling
|
||||||
if "access_token" in login_response:
|
if "access_token" in login_response:
|
||||||
self.access_token = cast(str, login_response["access_token"])
|
self.access_token = cast(str, login_response["access_token"])
|
||||||
logger.debug("Access token granted")
|
logger.info("Access token granted")
|
||||||
login_form.clear()
|
login_form.clear()
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -395,7 +395,6 @@ class _AuthState:
|
|||||||
raise CaptchaRequired()
|
raise CaptchaRequired()
|
||||||
|
|
||||||
if hasattr(self, "access_token"):
|
if hasattr(self, "access_token"):
|
||||||
logger.debug("Access token granted")
|
|
||||||
return self.access_token
|
return self.access_token
|
||||||
raise MinerException("Login flow finished without setting the access token")
|
raise MinerException("Login flow finished without setting the access token")
|
||||||
|
|
||||||
@@ -451,7 +450,7 @@ class _AuthState:
|
|||||||
if not self._hasattrs("access_token", "user_id"):
|
if not self._hasattrs("access_token", "user_id"):
|
||||||
# looks like we're missing something
|
# looks like we're missing something
|
||||||
login_form: LoginForm = self._twitch.gui.login
|
login_form: LoginForm = self._twitch.gui.login
|
||||||
logger.debug("Checking login")
|
logger.info("Checking login")
|
||||||
login_form.update(_("gui", "login", "logging_in"), None)
|
login_form.update(_("gui", "login", "logging_in"), None)
|
||||||
for attempt in range(2):
|
for attempt in range(2):
|
||||||
cookie = jar.filter_cookies(BASE_URL)
|
cookie = jar.filter_cookies(BASE_URL)
|
||||||
@@ -459,7 +458,7 @@ class _AuthState:
|
|||||||
self.access_token = await self._login()
|
self.access_token = await self._login()
|
||||||
cookie["auth-token"] = self.access_token
|
cookie["auth-token"] = self.access_token
|
||||||
elif not hasattr(self, "access_token"):
|
elif not hasattr(self, "access_token"):
|
||||||
logger.debug("Restoring session from cookie")
|
logger.info("Restoring session from cookie")
|
||||||
self.access_token = cookie["auth-token"].value
|
self.access_token = cookie["auth-token"].value
|
||||||
# validate the auth token, by obtaining user_id
|
# validate the auth token, by obtaining user_id
|
||||||
async with self._twitch.request(
|
async with self._twitch.request(
|
||||||
@@ -470,7 +469,7 @@ class _AuthState:
|
|||||||
status = response.status
|
status = response.status
|
||||||
if status == 401:
|
if status == 401:
|
||||||
# the access token we have is invalid - clear the cookie and reauth
|
# the access token we have is invalid - clear the cookie and reauth
|
||||||
logger.debug("Restored session is invalid")
|
logger.info("Restored session is invalid")
|
||||||
assert BASE_URL.host is not None
|
assert BASE_URL.host is not None
|
||||||
jar.clear_domain(BASE_URL.host)
|
jar.clear_domain(BASE_URL.host)
|
||||||
continue
|
continue
|
||||||
@@ -481,7 +480,7 @@ class _AuthState:
|
|||||||
raise RuntimeError("Login verification failure")
|
raise RuntimeError("Login verification failure")
|
||||||
self.user_id = int(validate_response["user_id"])
|
self.user_id = int(validate_response["user_id"])
|
||||||
cookie["persistent"] = str(self.user_id)
|
cookie["persistent"] = str(self.user_id)
|
||||||
logger.debug(f"Login successful, user ID: {self.user_id}")
|
logger.info(f"Login successful, user ID: {self.user_id}")
|
||||||
login_form.update(_("gui", "login", "logged_in"), self.user_id)
|
login_form.update(_("gui", "login", "logged_in"), self.user_id)
|
||||||
# update our cookie and save it
|
# update our cookie and save it
|
||||||
jar.update_cookies(cookie, BASE_URL)
|
jar.update_cookies(cookie, BASE_URL)
|
||||||
@@ -1089,7 +1088,7 @@ class Twitch:
|
|||||||
"""
|
"""
|
||||||
Called by a Channel when it goes online (after pending).
|
Called by a Channel when it goes online (after pending).
|
||||||
"""
|
"""
|
||||||
logger.debug(f"{channel.name} goes ONLINE")
|
logger.info(f"{channel.name} goes ONLINE")
|
||||||
if (
|
if (
|
||||||
self.can_watch(channel) # we can watch the channel that just got ONLINE
|
self.can_watch(channel) # we can watch the channel that just got ONLINE
|
||||||
and self.should_switch(channel) # and we should!
|
and self.should_switch(channel) # and we should!
|
||||||
@@ -1110,7 +1109,7 @@ class Twitch:
|
|||||||
self.print(_("status", "goes_offline").format(channel=channel.name))
|
self.print(_("status", "goes_offline").format(channel=channel.name))
|
||||||
self.change_state(State.CHANNEL_SWITCH)
|
self.change_state(State.CHANNEL_SWITCH)
|
||||||
else:
|
else:
|
||||||
logger.debug(f"{channel.name} goes OFFLINE")
|
logger.info(f"{channel.name} goes OFFLINE")
|
||||||
|
|
||||||
@task_wrapper
|
@task_wrapper
|
||||||
async def process_drops(self, user_id: int, message: JsonType):
|
async def process_drops(self, user_id: int, message: JsonType):
|
||||||
|
|||||||
+4
-2
@@ -256,10 +256,12 @@ class Websocket:
|
|||||||
elif raw_message.type is WSMsgType.CLOSING:
|
elif raw_message.type is WSMsgType.CLOSING:
|
||||||
pass # skip these
|
pass # skip these
|
||||||
elif raw_message.type is WSMsgType.ERROR:
|
elif raw_message.type is WSMsgType.ERROR:
|
||||||
logger.error(f"Websocket[{self._idx}] error: {format_traceback(raw_message.data)}")
|
ws_logger.error(
|
||||||
|
f"Websocket[{self._idx}] error: {format_traceback(raw_message.data)}"
|
||||||
|
)
|
||||||
raise WebsocketClosed()
|
raise WebsocketClosed()
|
||||||
else:
|
else:
|
||||||
logger.error(f"Websocket[{self._idx}] error: Unknown message: {raw_message}")
|
ws_logger.error(f"Websocket[{self._idx}] error: Unknown message: {raw_message}")
|
||||||
|
|
||||||
def _handle_message(self, message):
|
def _handle_message(self, message):
|
||||||
# request the assigned topic to process the response
|
# request the assigned topic to process the response
|
||||||
|
|||||||
Reference in new issue
Block a user