From bfa0534f6dcdf2ab53bd9443dee5ddc269c7e768 Mon Sep 17 00:00:00 2001 From: hkc Date: Tue, 1 Nov 2022 14:33:47 +0300 Subject: [PATCH] uh, more logging? --- mastoposter/__init__.py | 2 +- mastoposter/__main__.py | 4 +++- mastoposter/filters/__init__.py | 2 +- mastoposter/filters/combined.py | 11 ++++++++--- mastoposter/integrations/discord/__init__.py | 2 +- mastoposter/integrations/telegram.py | 9 +++++++-- mastoposter/utils.py | 7 +++++++ 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/mastoposter/__init__.py b/mastoposter/__init__.py index 8217e28..a815d03 100644 --- a/mastoposter/__init__.py +++ b/mastoposter/__init__.py @@ -12,7 +12,7 @@ from mastoposter.integrations import ( ) from mastoposter.types import Status -logger = getLogger(__name__) +logger = getLogger() def load_integrations_from(config: ConfigParser) -> List[FilteredIntegration]: diff --git a/mastoposter/__main__.py b/mastoposter/__main__.py index a5c4ae7..ab38d11 100644 --- a/mastoposter/__main__.py +++ b/mastoposter/__main__.py @@ -37,6 +37,7 @@ async def listen( ): logger.info("Starting listening...") async for status in source(**kwargs): + logger.info("New status: %s", status.uri) logger.debug("Got status: %r", status) if status.account.id != user: logger.info( @@ -91,7 +92,8 @@ def main(config_path: str): ) account = Account.from_dict(rq.json()) user_id = account.id - logger.info("account.id=%s", user_id) + + logger.info("account.id=%s", user_id) url = "wss://{}/api/v1/streaming".format(conf["main"]["instance"]) diff --git a/mastoposter/filters/__init__.py b/mastoposter/filters/__init__.py index 015245c..79fbe23 100644 --- a/mastoposter/filters/__init__.py +++ b/mastoposter/filters/__init__.py @@ -11,7 +11,7 @@ from mastoposter.filters.text import TextFilter # NOQA from mastoposter.filters.spoiler import SpoilerFilter # NOQA from mastoposter.filters.visibility import VisibilityFilter # NOQA -logger = getLogger(__name__) +logger = getLogger("filters") def run_filters(filters: List[FilterInstance], status: Status) -> bool: diff --git a/mastoposter/filters/combined.py b/mastoposter/filters/combined.py index 0700cd4..49f1174 100644 --- a/mastoposter/filters/combined.py +++ b/mastoposter/filters/combined.py @@ -12,7 +12,7 @@ class CombinedFilter(BaseFilter, filter_name="combined"): } def __init__(self, filter_names: List[str], operator: str): - self.filter_names = filter_names + self._filter_names = filter_names self._operator_name = operator self.operator = self.OPERATORS[self._operator_name] self.filters: List[FilterInstance] = [] @@ -30,7 +30,7 @@ class CombinedFilter(BaseFilter, filter_name="combined"): super().post_init(filters, config) self.filters = [ self.new_instance(name, config["filter/" + name.lstrip("~!")]) - for name in self.filter_names + for name in self._filter_names ] def __call__(self, post: Status) -> bool: @@ -39,7 +39,12 @@ class CombinedFilter(BaseFilter, filter_name="combined"): return self.operator([f[1](post) ^ f[0] for f in self.filters]) def __repr__(self): + if self.filters: + return ( + f"Filter:combined(op={self._operator_name}, " + f"filters={self.filters!r})" + ) return ( f"Filter:combined(op={self._operator_name}, " - f"filters={self.filters!r})" + f"filters={self._filter_names!r}, loaded=False)" ) diff --git a/mastoposter/integrations/discord/__init__.py b/mastoposter/integrations/discord/__init__.py index bc674d4..04d4d00 100644 --- a/mastoposter/integrations/discord/__init__.py +++ b/mastoposter/integrations/discord/__init__.py @@ -11,7 +11,7 @@ from mastoposter.integrations.discord.types import ( ) from mastoposter.types import Status -logger = getLogger(__name__) +logger = getLogger("integrations.discord") class DiscordIntegration(BaseIntegration): diff --git a/mastoposter/integrations/telegram.py b/mastoposter/integrations/telegram.py index 3a3f185..9b9889c 100644 --- a/mastoposter/integrations/telegram.py +++ b/mastoposter/integrations/telegram.py @@ -9,7 +9,7 @@ from mastoposter.types import Attachment, Poll, Status from emoji import emojize -logger = getLogger(__name__) +logger = getLogger("integrations.telegram") @dataclass @@ -93,7 +93,7 @@ class TelegramIntegration(BaseIntegration): ) if not response.ok: logger.error("TG error: %r", response.error) - logger.info("parameters: %r", kwargs) + logger.error("parameters: %r", kwargs) return response async def _post_plaintext(self, text: str) -> TGResponse: @@ -135,6 +135,11 @@ class TelegramIntegration(BaseIntegration): if attachment.type not in allowed_medias: continue if attachment.type not in MEDIA_COMPATIBILITY: + logger.warning( + "attachment %r is not in %r", + attachment.type, + MEDIA_COMPATIBILITY, + ) continue allowed_medias &= MEDIA_COMPATIBILITY[attachment.type] media_list.append( diff --git a/mastoposter/utils.py b/mastoposter/utils.py index 14e6bcc..3474908 100644 --- a/mastoposter/utils.py +++ b/mastoposter/utils.py @@ -1,8 +1,11 @@ from configparser import ConfigParser from html import escape +from logging import getLogger from typing import Callable, Dict from bs4.element import Tag, PageElement +logger = getLogger("utils") + def md_escape(text: str) -> str: return ( @@ -24,9 +27,13 @@ def normalize_config(conf: ConfigParser): normalized_key = k.replace(" ", "_").replace("-", "_") if k == normalized_key: continue + logger.info( + "moving %r.%r -> %r.%r", section, k, section, normalized_key + ) conf[section][normalized_key] = v _remove.add(k) for k in _remove: + logger.info("removing key %r.%r", section, k) del conf[section][k]