Using request object in settings.py for custom logging

52 views
Skip to first unread message

Nikunj Badjatya

unread,
Nov 24, 2015, 5:22:04 AM11/24/15
to Django users
Hello,

Currently for our application, all django logs are generated and kept at '/var/log/django.log'
We want to have different log files for different clients. i.e.
/var/log/client-1/django.log
/var/log/client-2/django.log
/var/log/client-3/django.log
....
....

The request object has information about the logged in user (and thus client). These inturn are stored in a mysql database.

How can django log file path be modified dynamically such that when client-1 is using the application, his logs go into '/var/log/client-1/django.log' and so on for other clients ?

Using Django 1.6.11 and Python 2.7.
'LOGGING' is defined in settings.py.

Thanks.

Jani Tiainen

unread,
Nov 24, 2015, 6:24:36 AM11/24/15
to django...@googlegroups.com
Hi,

Problem is that you quite certainly have different users and several processess/threads which would lead logging configuration per request.

Is there a reason you don't use something like sites framework to differentiate clients?
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c7c7d27a-2804-4993-8bb9-dd9c3fb7eeab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikunj Badjatya

unread,
Nov 25, 2015, 4:45:48 AM11/25/15
to Django users
Thank you for your response.
Well our application is single site only. AFAIK, sites framework is useful when your django application serves multiple sites.
Can you throw some more light on what can be achieved using sites ?

I would like to evaluate all available options.

Thanks.

Jani Tiainen

unread,
Nov 25, 2015, 4:55:26 AM11/25/15
to django...@googlegroups.com
Well sites framework makes possible to do for example multitenancy inside database.

But apparently that is not your case. So why you like to log something per user? What's the real usecase here?

Nikunj Badjatya

unread,
Nov 25, 2015, 5:02:23 AM11/25/15
to Django users
We want to separate out activity per client. This can be useful in many ways. Ex. 1) easier debugging of issues. 2) Running some analytics per client by looking at his log file. 3) Clients which are no longer a customer, their logs can be safely moved to lower storage tiers. etc.
Basically to help in debugging and maintenance of the application.

Thoughts?

Nikunj Badjatya

unread,
Nov 27, 2015, 4:06:31 AM11/27/15
to Django users
Anyone with any idea how to solve this problem?

Thanks in advance.


Reply all
Reply to author
Forward
0 new messages