Raekkeri/django-requestlogs

Include header

Closed this issue · 8 comments

Hello,

how to include a header in the request dictionary?

It can be done by extending the entry serializer. I added a test case for this, see commit 31f6d22

So basically

class RequestHeaderEntry(BaseEntrySerializer):
    class RequestSerializer(BaseRequestSerializer):
        accept_header = serializers.CharField(source='request.META.HTTP_ACCEPT')

    request = RequestSerializer()

And then use RequestHeaderEntry as SERIALIZER_CLASS in settings.py.

Of course the example above expects that the HTTP_ACCEPT is always present. You can add more logic to getting the header value e.g. by using SerializerMethodField (https://www.django-rest-framework.org/api-guide/fields/#serializermethodfield).

Hello @Raekkeri ,

I have made changes to add request headers into the dict of request and want to push it in new branch, but not able to push it, could you please allow to push. want to contribute in this plugin.

Hello @Raekkeri ,

And how to log only Error requests, not 200 status_code request?

Hi,
please create the pull request by forking the repository first to yourself, then creating pull request from that fork (as it is the convention in GitHub).

Hey @Raekkeri ,

Did that. Thanks

And how to log only Error requests, not 200 status_code request?

Hi @chiragkanhasoft
I haven't planned this kind of behaviour previously, but for now the logic should probably go into the STORAGE_CLASS (and its store(..) function), e.g.:

from requestlogs.storages import LoggingStorage

class ErrorsOnlyStorage(LoggingStorage):
    def store(self, entry):
        if entry.response.status_code >= 400:
            return super().store(entry)

hi @Raekkeri ,

I have added a logic to store log for some defined URLs. would you like to include it?

Thanks

Implemented here: #28