logging_4.py 809 B

12345678910111213141516171819202122232425262728
  1. def error(message):
  2. DirLogs = settings.BASE_DIR + "/log"
  3. if not os.path.exists(DirLogs):
  4. try:
  5. os.mkdir(DirLogs)
  6. except OSError:
  7. return
  8. DirLogs = settings.BASE_DIR + "/log/error"
  9. if not os.path.exists(DirLogs):
  10. try:
  11. os.mkdir(DirLogs)
  12. except OSError:
  13. return
  14. date = datetime.now()
  15. month = "0" if date.month < 10 else ""
  16. month += str(date.month)
  17. day = "0" if date.day < 10 else ""
  18. day += str(date.day)
  19. StrDate = "%s%s%s" % (str(date.year), month, day)
  20. file = open(DirLogs + '/errors_' + StrDate + '.log', 'a')
  21. my_file = File(file)
  22. my_file.write("[%s]: %s\n" % (
  23. str(datetime.now().strftime("%d-%m-%Y %H:%M:%S")),
  24. str(message)))
  25. my_file.closed
  26. file.closed