Is there a Django middleware/plugin that logs all

2019-02-13 11:15发布

I want to log every request that ever comes through my sever. Is there a plugin/middleware for this?

Ideally I'd like it to be queryable.

3条回答
贪生不怕死
2楼-- · 2019-02-13 11:34

You should keep the logging inside of your webserver, not in Django. Although it can log, it's not something you generally would want to do.

If you really want to though, here's an example middleware:

class RequestLoggingMiddleware(object):
    def process_request(self, request):
        syslog.syslog(' '.join([
            request.META['remote_addr'],
            request.get_full_path(),
        ]))
查看更多
【Aperson】
3楼-- · 2019-02-13 11:41

You best bet seems to be django-request.

查看更多
Melony?
4楼-- · 2019-02-13 11:43

Don't know if that's what you want, but django-sentry is a great app for logging errors that occur in your Django site. They can be shown in a (well-designed!) web interface, allowing for sorting like number of occurrences of an error etc.

If you just want to log requests, Apache's access.log should be enough. And I guess there are many tools for parsing and displaying the content of Apache logs.

查看更多
登录 后发表回答