Store Django Log messages in a database?

后端 未结 4 409
無奈伤痛
無奈伤痛 2021-02-05 11:51

Django (the python web framework) uses python\'s logging system to store logs.

Is there an easy way to store log messages in a database, and then allow admin users to lo

相关标签:
4条回答
  • 2021-02-05 12:24

    Just use Sentry. Raven, the Django piece of the functionality hooks into the logging framework, so in addition to collecting errors from your app, any custom log messages should show up as well.

    0 讨论(0)
  • 2021-02-05 12:24

    try django-requests. I've tried it and it basically just puts the request logs in a table called requests.

    0 讨论(0)
  • 2021-02-05 12:27

    check django-db-logger

    it takes less than a minute to integrate

    https://github.com/CiCiUi/django-db-logger

    0 讨论(0)
  • 2021-02-05 12:45

    Apart from the obvious choice of Sentry, for the sake of exercise, there is a nice blog article titled "Creating custom log handler that logs to database models in django" in the "James Lin Blog", which briefly explains how to do this using a second database, with code samples.

    The code is adapted from the standard Python RotatingFileHandler:

    ...The RotatingFileHandler allows you to specify which file to write to and rotate files, therefore my DBHandler should also allow you to specify which model to insert to and specify expiry in settings, and best of all, on a standalone app.

    This could also be easily adapted for using a single db.

    0 讨论(0)
提交回复
热议问题