I\'m using the standard python (2.5.2) logging module, specifically the RotatingFileHandler
, on a linux system. My application supports both a command-line interfa
Here's a complete solution for Django based on rob's solution. in my_module
:
import logging
import logging.handlers
import os
The class=
that happens during the logging configuration is evaluated in the namespace of the logging module, and by default this does not have a binding to handlers. So we have to put it in explicitly before we can extend it. See this SO article
logging.handlers = logging.handlers
It's this magical incantation that took me forever to find - I couldn't believe it did anything! Finally, Jon's class will load without errors.
class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):
def _open(self):
prevumask = os.umask(0o002)
rtv = logging.handlers.RotatingFileHandler._open(self)
os.umask(prevumask)
return rtv
To use this for Django add the following this in the settings file
from my_module import GroupWriteRotatingFileHandler
logging.handlers.GroupWriteRotatingFileHandler = GroupWriteRotatingFileHandler
And then in LOGGING['handlers']['file']
you have
'class': 'logging.handlers.GroupWriteRotatingFileHandler'