I need to log some business events in my Django 1.4 application. For example, when user send a refferal email, or user makes a purchase. And so on. This event log will be used for some busness analytics. Is there any best practisies for doing this in e-commercial applications? May be a service or django module? I've never developed such systems before and I need some advice.
Asked
Active
Viewed 2,583 times
2 Answers
6
I know you're talking about using the built-in but just for give another option, I usually use a model to store log action in some e-commerce pages, such as:
class MyLog(models.Model):
LOG_ACTIONS = (
('login', 'User logged in'),
('delete_object', 'User delete object'),
('create_object', 'User create object'),
('buy_object', 'User buy object'),
# ... ... ...
# Whatever you need here
)
user = models.ForeignKey(User)
action = models.CharField(max_length=20, default='login', choices=LOG_ACTIONS, verbose_name= 'action')
date = models.DateTimeField(auto_now_add=True, verbose_name='date')
class Meta:
ordering = ['-dt']
verbose_name = 'Action log'
verbose_name_plural = 'Actions log'
The example is simplified, you can use as many fields as you need and as many log actions as you need.
So when you do any action that have to be in the log, just create an object for MyLog, and when you want to get all log actions, just get MyLog objects, and you can filter them by date, user or any field you put in there.
Hope it helps!

AlvaroAV
- 10,335
- 12
- 60
- 91
-
1Looks like this is the best way to do logging. I've thought about something like this. Thanks! – Paul May 28 '14 at 07:38
-
You're welcome! I usually choose this option because I can customize the log in function of the project I'm working on. – AlvaroAV May 28 '14 at 08:31
-
How do I hook this up to a view. Assuming I upload a file from a view, it should be added to the log? – Bernard 'Beta Berlin' Parah Aug 23 '16 at 15:30
-
Maybe you should ask a different question, I'm not sure I'm understanding what you're looking for – AlvaroAV Aug 23 '16 at 15:31
-
Do you think it will be better to ask this as a separate question? If, no you can let me know how to proceed, then I continue researching. – Bernard 'Beta Berlin' Parah Aug 23 '16 at 15:31
-
If you want we can chat about it, or you can ask a separate question and I will try to answer you there – AlvaroAV Aug 23 '16 at 15:32
-
Maybe we chat since I am not entirely sure of how to phrase the question. – Bernard 'Beta Berlin' Parah Aug 23 '16 at 15:33
-
Check this room out http://chat.stackoverflow.com/rooms/121643/django-logging-doubts – AlvaroAV Aug 23 '16 at 15:37
2
There's a built-in logging app. Check the 1.4 docs: https://docs.djangoproject.com/en/1.4/topics/logging/

xjtian
- 966
- 1
- 7
- 15
-
Yes, I know about it. I thought there any more specific application. Have you ever used django logger for tracking users activity? – Paul May 28 '14 at 05:21
-
1[Use the logger like this](http://stackoverflow.com/questions/5739830/simple-log-to-file-example-for-django-1-3) – John Mee May 28 '14 at 05:32