You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526
  1. from logging import FileHandler as BaseFileHandler
  2. import os
  3. class EnvFileHandler(BaseFileHandler):
  4. """
  5. Custom filehandler that uses the LOG_ROOT setting to determine the folder
  6. to store log files in.
  7. We have to do some tricky stuff to avoid circular imports. To this end,
  8. we pass /dev/null to the parent handler but specify opening to be delayed.
  9. Then when we try to first open the file, we join the LOG_ROOT with the
  10. passed filename.
  11. """
  12. def __init__(self, filename, *args, **kwargs):
  13. self.filename = filename
  14. kwargs['delay'] = True
  15. BaseFileHandler.__init__(self, "/dev/null", *args, **kwargs)
  16. def _open(self):
  17. # We import settings here to avoid a circular reference as this module
  18. # will be imported when settings.py is executed.
  19. from django.conf import settings
  20. self.baseFilename = os.path.join(settings.LOG_ROOT, self.filename)
  21. return BaseFileHandler._open(self)