On 27 jan, 11:31, Rama <
ramaakrish...@gmail.com> wrote:
> please look at the below logging.conf file.
http://dpaste.com/hold/113443/
>
> For RotatingFileHandler [handler_rfileHandler] i have hard coded the log
> file path as "/home/rama/djangoprojects/doloto/logs/logs.txt"
> how to avoid such hard coding of log file path in the logging.conf file.
1/ in your settings.py file:
LOG_PATH = "/whatever/you/want.log"
2/ in the code calling logging.config.fileConfig:
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
try:
LOG_PATH = settings.LOG_PATH
except AttributeError:
raise ImproperlyConfigured("missing configuration : LOG_PATH")
import logging
logging.config.fileConfig(LOG_PATH, defaults=dict(log_path=LOG_PATH))
3/ in your logging.conf
[handler_rfileHandler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=(%(log_path)s,'a',5000000,5)
Not tested, but this should do the trick. If it doesn't, you may have
to provide the whole value for 'args', ie:
in 2/
log_args = (LOG_PATH, 'a', 5000000, 5)
logging.config.fileConfig(LOG_PATH, defaults=dict(log_args=log_args))
in 3/
args=%(log_args)s
HTH