diff --git a/src/iSponsorBlockTV/helpers.py b/src/iSponsorBlockTV/helpers.py index ea29003..b17dc3a 100644 --- a/src/iSponsorBlockTV/helpers.py +++ b/src/iSponsorBlockTV/helpers.py @@ -152,8 +152,20 @@ def cli(ctx, data, debug, setup, setup_cli): ctx.ensure_object(dict) ctx.obj["data_dir"] = data ctx.obj["debug"] = debug + + logger = logging.getLogger() + ctx.obj["logger"] = logger + sh = logging.StreamHandler() + sh.setFormatter( + logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + ) + logger.addHandler(sh) + if debug: - logging.basicConfig(level=logging.DEBUG) + logger.setLevel(logging.DEBUG) + else: + logger.setLevel(logging.INFO) + if ctx.invoked_subcommand is None: if setup: ctx.invoke(setup_command) diff --git a/src/iSponsorBlockTV/main.py b/src/iSponsorBlockTV/main.py index 223227b..5ab26f2 100644 --- a/src/iSponsorBlockTV/main.py +++ b/src/iSponsorBlockTV/main.py @@ -18,16 +18,6 @@ class DeviceListener: self.cancelled = False self.logger = logging.getLogger(f"iSponsorBlockTV-{device.screen_id}") self.web_session = web_session - if debug: - self.logger.setLevel(logging.DEBUG) - else: - self.logger.setLevel(logging.INFO) - sh = logging.StreamHandler() - sh.setFormatter( - logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") - ) - self.logger.addHandler(sh) - self.logger.info("Starting device") self.lounge_controller = ytlounge.YtLoungeApi( device.screen_id, config, api_helper, self.logger ) @@ -60,6 +50,7 @@ class DeviceListener: except BaseException: await asyncio.sleep(10) while not (await self.is_available()) and not self.cancelled: + self.logger.debug("Waiting for device to be available") await asyncio.sleep(10) try: await lounge_controller.connect() @@ -67,6 +58,7 @@ class DeviceListener: pass while not lounge_controller.connected() and not self.cancelled: # Doesn't connect to the device if it's a kids profile (it's broken) + self.logger.debug("Waiting for device to be connected") await asyncio.sleep(10) try: await lounge_controller.connect() @@ -76,7 +68,7 @@ class DeviceListener: "Connected to device %s (%s)", lounge_controller.screen_name, self.name ) try: - self.logger.info("Subscribing to lounge") + self.logger.debug("Subscribing to lounge") sub = await lounge_controller.subscribe_monitored(self) await sub except BaseException: