Instead of solving this problem on django side, I'd recommend using a tool such as logrotate for this problem http://www.rackspace.com/knowledge_center/article/understanding-logrotate-utility
You can customise it to your needs, daily, weekly or per size basis. One problem with solving it on django side would be, as the django settings are loaded when you restart the server, and in production you may not want to load the server every day, the TODAY_STRING would stay as the first day the settings are loaded. So it's a better practice to solve the logging on server side. Best. - Serdar Dalgıç <s...@serdardalgic.org> FLOSS Developer, Life & Nature Hacker twitter: https://twitter.com/serdaroncode https://twitter.com/serdarintowild On Mon, Nov 9, 2015 at 4:40 AM, tolerious feng <toleriousn...@gmail.com> wrote: > I want to write django log to different, especially I want to log daily > log file, such as 2015-11-09-log.txt 2015-11-10-log.txt, this is my > settings.py file: > > TODAY_STRING = datetime.datetime.now().strftime("%F") > TODAY_LOG_DIR = os.path.dirname(__file__) + "/log/" + TODAY_STRING > # TODAY_LOG_DIR = "/log/" + TODAY_STRING > print "*******" > print SITE_SRC_ROOT > print TODAY_LOG_DIR > print os.path.join(SITE_SRC_ROOT, TODAY_LOG_DIR, "todaytotal.log") > print os.path.join(SITE_SRC_ROOT, "log/" + TODAY_STRING, "todaytotal.log"), > if os.path.exists(TODAY_LOG_DIR): > pass > else: > os.mkdir(TODAY_LOG_DIR) > > LOGGING = { > 'version': 1, > 'disable_existing_loggers': False, > 'formatters': { > 'verbose': { > 'format': '%(levelname)s: %(asctime)s %(module)s %(process)d > %(thread)d %(message)s %(filename)s:%(funcName)s:%(lineno)d' > } > }, > 'handlers': { > 'total': { > 'level': 'DEBUG', > 'class': 'logging.FileHandler', > 'formatter': 'verbose', > 'filename': os.path.join(SITE_SRC_ROOT, "log", "total.txt"), > }, > 'todaytotal': { > 'level': 'DEBUG', > 'class': 'logging.FileHandler', > 'formatter': 'verbose', > 'filename': os.path.join(SITE_SRC_ROOT, "log/" + TODAY_STRING, > "todaytotal.txt"), > }, > 'dengbin': { > 'level': 'DEBUG', > 'class': 'logging.FileHandler', > 'formatter': 'verbose', > 'filename': os.path.join(SITE_SRC_ROOT, "log/" + TODAY_STRING, > 'dengbin.txt'), > }, > 'haiyang': { > 'level': 'DEBUG', > 'class': 'logging.FileHandler', > 'formatter': 'verbose', > 'filename': os.path.join(SITE_SRC_ROOT, "log/" + TODAY_STRING, > 'haiyang.txt'), > }, > 'meibo': { > 'level': 'DEBUG', > 'class': 'logging.FileHandler', > 'formatter': 'verbose', > 'filename': os.path.join(SITE_SRC_ROOT, "log/" + TODAY_STRING, > "meibo.txt"), > }, > 'xiecheng': { > 'level': 'DEBUG', > 'class': 'logging.FileHandler', > 'formatter': 'verbose', > 'filename': os.path.join(SITE_SRC_ROOT, "log/" + TODAY_STRING, > 'xiecheng.txt'), > }, > 'tolerious': { > 'level': 'DEBUG', > 'class': 'logging.FileHandler', > 'formatter': 'verbose', > 'filename': os.path.join(SITE_SRC_ROOT, "log/" + TODAY_STRING, > 'tolerious.txt'), > } > }, > 'loggers': { > 'xiecheng': { > 'handlers': ['xiecheng', 'todaytotal', 'meibo', 'total'], > 'propagate': False, > 'level': 'DEBUG', > }, > 'dengbin': { > 'handlers': ['dengbin', 'todaytotal', 'meibo', 'total'], > 'propagate': False, > 'level': 'DEBUG', > }, > 'haiyang': { > 'handlers': ['haiyang', 'todaytotal', 'meibo', 'total'], > 'propagate': False, > 'level': 'DEBUG', > }, > 'tolerious': { > 'handlers': ['tolerious', 'todaytotal', 'meibo', 'total'], > 'propagate': False, > 'level': 'DEBUG', > } > }, > 'root': { > 'handlers': ['total'], > 'level': 'DEBUG', > }, > } > > > but this doesn't work, it only log 2015-11-09-log.txt, when today is > 2015-11-10, 2015-11-10-log.txt not generated. > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@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/0ca4d5be-88de-4e2e-afee-1c3b65bc3132%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/0ca4d5be-88de-4e2e-afee-1c3b65bc3132%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@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/CAJH%2BopqUd8Q1rpg-3bEQ%2BOz%2B3noCse_Zb%2BvYmPaZQ10f8dUFjA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.