Hi Thomas,
-- The primary purpose of logging is to catch and examine errors. If something went wrong, you want to know when and why. Logging to a database increases the complexity and greatly increases the number of things that can go wrong. The last thing you want to find out when retracing an error is that you don't have any logs because the logging system failed. You may also need to log errors that happened during startup, before a database connection can be established. Logging to file is the simplest method, and has the least chance of failure. That's why you should always log to file.
The two options are not mutually exclusive. Like you said, times have changed, and the overhead to store logs both in a file and in a database are nowadays acceptable. If you have a good reason to store the logs in a database, then go ahead. Just remember that it should be in addition to file-based logging.
Kind regards,
Marten
On Tuesday, April 4, 2017 at 2:18:42 PM UTC+2, guettli wrote:
On Tuesday, April 4, 2017 at 2:18:42 PM UTC+2, guettli wrote:
In the past I was told: Don't store logs in the database.
Time (and hardware) has changed.
I think it is time to store logs where I have great tools for analyzing logs.
Storing in a model which I can access via django orm is my current strategy.
It seems no one has done this before. I could not find such a project up to now.
My first draft looks like this:
class Log(models.Model):
datetime=models.DateTimeField(default =datetime.datetime.now, db_index=True)
data=jsonfield.JSONField()
host=models.CharField(max_length =256, default='localhost', db_index=True)
system=models.CharField(max_length =256, default='', db_index=True)
I am missing two things:
Missing1: Log level: INFO, WARN, ...
Missing2: A way to store exceptions.
What do you think?
What's wrong with this, what could be improved?
Regards,
Thomas Güttler
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/21746446-93c7-40d7-b2fa-6adaad9f4aee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment