Django logs: any tutorial to log to a file

2019-05-23 09:11发布

问题:

I am working with a django project, I haven't started. The developed working on the project left. During the knowledge transfer, it was told to me that all the events are logged to the database. I don't find the database interface useful to search for logs and sometimes they don't even log(I might be wrong). I want to know, if there is an easy tutorial that explains how to enable logging in Django with minimal configuration changes.

Thank you
Bala

回答1:

If you are talking about the Django admin log (the one that shows on the right side of the main page of the admin interface), you could just enable an admin model for the log itself.

Open the admin.py for one of your django apps and add this:

from django.contrib.admin.models import LogEntry

class LogEntryAdmin(admin.ModelAdmin):
    list_display = ('content_type', 'user', 'action_time')

admin.site.register(LogEntry, LogEntryAdmin)

It will give you a barebones interface for looking at the log.

Remember that log is only logging whatever happens through the admin interface itself.