Changed default level to ERROR, added TG API logs

This commit is contained in:
Casey 2022-11-01 13:52:40 +03:00
parent 95c9a523e0
commit fd05f39f4a
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
3 changed files with 15 additions and 5 deletions

View File

@ -65,7 +65,7 @@ def load_integrations_from(config: ConfigParser) -> List[FilteredIntegration]:
async def execute_integrations( async def execute_integrations(
status: Status, sinks: List[FilteredIntegration] status: Status, sinks: List[FilteredIntegration]
) -> List[Optional[str]]: ) -> List[Optional[str]]:
logger.debug("Executing integrations...") logger.info("Executing integrations...")
return await gather( return await gather(
*[sink[0](status) for sink in sinks if run_filters(sink[1], status)], *[sink[0](status) for sink in sinks if run_filters(sink[1], status)],
return_exceptions=True, return_exceptions=True,

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from asyncio import run from asyncio import run
from configparser import ConfigParser, ExtendedInterpolation from configparser import ConfigParser, ExtendedInterpolation
from logging import DEBUG, Formatter, StreamHandler, getLogger from logging import INFO, Formatter, StreamHandler, getLogger
from sys import stdout from sys import stdout
from mastoposter import execute_integrations, load_integrations_from from mastoposter import execute_integrations, load_integrations_from
from mastoposter.integrations import FilteredIntegration from mastoposter.integrations import FilteredIntegration
@ -19,9 +19,9 @@ VERIFY_CREDS_TEMPLATE = "https://{instance}/api/v1/accounts/verify_credentials"
logger = getLogger() logger = getLogger()
def init_logger(loglevel: int = DEBUG): def init_logger(loglevel: int = INFO):
stdout_handler = StreamHandler(stdout) stdout_handler = StreamHandler(stdout)
stdout_handler.setLevel(DEBUG) stdout_handler.setLevel(loglevel)
formatter = Formatter("[%(asctime)s][%(levelname)5s:%(name)s] %(message)s") formatter = Formatter("[%(asctime)s][%(levelname)5s:%(name)s] %(message)s")
stdout_handler.setFormatter(formatter) stdout_handler.setFormatter(formatter)
logger.addHandler(stdout_handler) logger.addHandler(stdout_handler)
@ -39,6 +39,12 @@ async def listen(
async for status in source(**kwargs): async for status in source(**kwargs):
logger.debug("Got status: %r", status) logger.debug("Got status: %r", status)
if status.account.id != user: if status.account.id != user:
logger.info(
"Skipping status %s (account.id=%r != %r)",
status.uri,
status.account.id,
user,
)
continue continue
# TODO: add option/filter to handle that # TODO: add option/filter to handle that

View File

@ -88,9 +88,13 @@ class TelegramIntegration(BaseIntegration):
async def _tg_request(self, method: str, **kwargs) -> TGResponse: async def _tg_request(self, method: str, **kwargs) -> TGResponse:
url = API_URL.format(self.token, method) url = API_URL.format(self.token, method)
async with AsyncClient() as client: async with AsyncClient() as client:
return TGResponse.from_dict( response = TGResponse.from_dict(
(await client.post(url, json=kwargs)).json(), kwargs (await client.post(url, json=kwargs)).json(), kwargs
) )
if not response.ok:
logger.error("TG error: %r", response.error)
logger.info("parameters: %r", kwargs)
return response
async def _post_plaintext(self, text: str) -> TGResponse: async def _post_plaintext(self, text: str) -> TGResponse:
logger.debug("Sending HTML message: %r", text) logger.debug("Sending HTML message: %r", text)