kopia lustrzana https://gitlab.com/marnanel/chapeau
log_one_message, a start at a common logging system for messages.
Submitted messages aren't currently logged because the whole message submission system is currently broken.status-serialisers
rodzic
f0c3d08e35
commit
26a56611a2
|
@ -96,3 +96,23 @@ def is_local(url):
|
|||
|
||||
parsed_url = urlparse(url)
|
||||
return parsed_url.hostname in settings.ALLOWED_HOSTS
|
||||
|
||||
def log_one_message(
|
||||
direction = None,
|
||||
body = None,
|
||||
):
|
||||
"""
|
||||
Writes a message to the "kepi" logger at DEBUG level.
|
||||
FIXME There must be a better way to do this.
|
||||
"""
|
||||
|
||||
if body is not None and '@context' in body:
|
||||
body = body.copy()
|
||||
del body['@context']
|
||||
|
||||
if direction:
|
||||
logger.debug(f"== Message %s == %s",
|
||||
direction, body)
|
||||
else:
|
||||
logger.debug(f"== Message == %s",
|
||||
body)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
from kepi.bowler_pub import ATSIGN_CONTEXT
|
||||
import kepi.bowler_pub.validation
|
||||
from kepi.bowler_pub.utils import configured_url, short_id_to_url, uri_to_url, is_local
|
||||
from kepi.bowler_pub.utils import *
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
import django.views
|
||||
from django.http import HttpResponse, JsonResponse, Http404
|
||||
|
@ -78,9 +78,13 @@ class KepiView(django.views.View):
|
|||
return result
|
||||
|
||||
data = self._render_object(result)
|
||||
logger.debug(' -- rendered to %s', data)
|
||||
|
||||
log_one_message(
|
||||
direction=f"response to {request.path}",
|
||||
body=data,
|
||||
)
|
||||
|
||||
httpresponse = self._to_httpresponse(data)
|
||||
logger.debug(' -- as HttpResponse, %s', httpresponse)
|
||||
return httpresponse
|
||||
|
||||
def _to_httpresponse(self, data):
|
||||
|
|
|
@ -15,7 +15,7 @@ import random
|
|||
from django.http.request import HttpRequest
|
||||
from django.conf import settings
|
||||
from urllib.parse import urlparse
|
||||
from kepi.bowler_pub.utils import configured_url, as_json, is_local
|
||||
from kepi.bowler_pub.utils import *
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
|
@ -347,6 +347,11 @@ def deliver(
|
|||
)
|
||||
message.save()
|
||||
|
||||
log_one_message(
|
||||
direction = "outgoing",
|
||||
body = activity,
|
||||
)
|
||||
|
||||
logger.info('activity %d: begin delivery: %s',
|
||||
message.pk, message.content)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ from django.http.request import HttpRequest
|
|||
from django.conf import settings
|
||||
from urllib.parse import urlparse
|
||||
from kepi.trilby_api.models import *
|
||||
from kepi.bowler_pub.utils import log_one_message
|
||||
from kepi.sombrero_sendpub.webfinger import get_webfinger
|
||||
|
||||
def fetch(address,
|
||||
|
@ -275,6 +276,11 @@ def _fetch_remote(address, wanted):
|
|||
|
||||
return result
|
||||
|
||||
log_one_message(
|
||||
direction = "retrieved",
|
||||
body = found,
|
||||
)
|
||||
|
||||
if 'type' not in found:
|
||||
logger.info("%s: retrieved JSON did not include a type; dropping",
|
||||
address)
|
||||
|
|
Ładowanie…
Reference in New Issue