On Jan 27, 2009, at 9:45 PM, Rama Vadakattu wrote:
>
> Eric,
> can you please show me the code snippet of specifying a logfile in
> settings.py.
Sure, here's something I use to keep a separate log of requests to an
RSS feed:
settings.py
#######
LOG_FILE = '/path/to/log/file.log'
feeds.py
######
import logging
from mysite.settings import LOG_FILE as lf
... # later in the file
feedlog = logging.FileHandler(lf)
form = logging.Formatter("%(asctime)s: %(message)s")
feedlog.setFormatter(form)
root = logging.getLogger('')
root.addHandler(feedlog)
def feedlogger(fn):
def wrapper(request,*args,**kwargs):
root.info("%s %s" % (request.path,
request.META.get('REMOTE_ADDR','')))
resp = fn(request,*args,**kwargs)
return resp
return wrapper
Then I import the feedlogger wrapper into my urls.py and wrap the
appropriate function there. The syntax for the logging handler is a
bit of a PITA, but that's just how Python logging works...
Hope that helps,
Eric
> On Jan 27, 6:37 pm, Eric Abrahamsen <[email protected]> wrote:
>> On Jan 27, 2009, at 9:28 PM, Thomas Guettler wrote:
>>
>>
>>
>>> Rama schrieb:
>>>> please look at the below logging.conf file.
>>>> ...
>>>> can any one guide me on how to avoid hardcoding of log file path ?
>>
>>> Hi,
>>
>>> I am not a logging expert, maybe there is a solution, but if you
>>> do your setup with python code, you can use e.g.
>>> os.environ['HOME'] or
>>> settings.FOO.
>>
>> This last (specifying a logfile in settings.py) has always worked
>> very
>> nicely for me.
>>
>> E
>>
>>> I never used a logging.conf file.
>>
>>> HTH,
>>> Thomas
>>
>>> BTW: This is a pure python question. You get more and better answers
>>> on the newsgroup comp.lang.python.
>>
>>> --
>>> Thomas Guettler,http://www.thomas-guettler.de/
>>> E-Mail: guettli (*) thomas-guettler + de
>>
>>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---