5

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.

Paul
  • 6,641
  • 8
  • 41
  • 56

2 Answers2

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
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