Tweak logging

This commit is contained in:
Thomas Sileo 2022-08-20 09:11:48 +02:00
parent 538af64955
commit 691ad500c6
4 changed files with 11 additions and 2 deletions

View file

@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
from typing import Any from typing import Any
import httpx import httpx
from loguru import logger
from markdown import markdown from markdown import markdown
from app import config from app import config
@ -135,6 +136,7 @@ async def fetch(
params: dict[str, Any] | None = None, params: dict[str, Any] | None = None,
disable_httpsig: bool = False, disable_httpsig: bool = False,
) -> RawObject: ) -> RawObject:
logger.info(f"Fetching {url} ({params=})")
check_url(url) check_url(url)
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
@ -342,6 +344,7 @@ def remove_context(raw_object: RawObject) -> RawObject:
async def post(url: str, payload: dict[str, Any]) -> httpx.Response: async def post(url: str, payload: dict[str, Any]) -> httpx.Response:
logger.info(f"Posting {url} ({payload=})")
check_url(url) check_url(url)
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:

View file

@ -187,7 +187,7 @@ async def httpsig_checker(
server=server, server=server,
) )
logger.debug(f"hsig={hsig}") # logger.debug(f"hsig={hsig}")
signed_string, signature_date = _build_signed_string( signed_string, signature_date = _build_signed_string(
hsig["headers"], hsig["headers"],
request.method, request.method,

View file

@ -3,6 +3,7 @@ import traceback
from datetime import datetime from datetime import datetime
from datetime import timedelta from datetime import timedelta
import httpx
from loguru import logger from loguru import logger
from sqlalchemy import func from sqlalchemy import func
from sqlalchemy import select from sqlalchemy import select
@ -116,6 +117,11 @@ async def process_next_incoming_activity(
next_activity.ap_object, next_activity.ap_object,
next_activity.sent_by_ap_actor_id, next_activity.sent_by_ap_actor_id,
) )
except httpx.TimeoutException as exc:
url = exc._request.url if exc._request else None
logger.error(f"HTTP timeout when fetching {url}")
next_activity.error = traceback.format_exc()
_set_next_try(next_activity)
except Exception: except Exception:
logger.exception("Failed") logger.exception("Failed")
next_activity.error = traceback.format_exc() next_activity.error = traceback.format_exc()

View file

@ -760,7 +760,7 @@ async def inbox(
db_session: AsyncSession = Depends(get_db_session), db_session: AsyncSession = Depends(get_db_session),
httpsig_info: httpsig.HTTPSigInfo = Depends(httpsig.enforce_httpsig), httpsig_info: httpsig.HTTPSigInfo = Depends(httpsig.enforce_httpsig),
) -> Response: ) -> Response:
logger.info(f"headers={request.headers}") # logger.info(f"headers={request.headers}")
payload = await request.json() payload = await request.json()
logger.info(f"{payload=}") logger.info(f"{payload=}")
await new_ap_incoming_activity(db_session, httpsig_info, payload) await new_ap_incoming_activity(db_session, httpsig_info, payload)