The only safe place is in the wsgi hook file in 1.2 or before. If Django 1.3 is able to do it in the settings then you will need to mimic how Django 1.3 does it. Settings are all in an object, so you may be able to override the base class LazyObject (utils/functional.py) which it used in LazySettings (conf/__init__.py). I have never done this so you are on your own here.
~Carl On Mon, Nov 29, 2010 at 10:43 AM, [email protected] <[email protected]> wrote: > > On Nov 29, 2010, at 9:51 AM, Carl Nobile wrote: > > Thanks for the quick response. > >> You need to initialize logging in the WSGI hook file, because the >> settings are lazily loaded. In other words you could start logging >> before the logger got instantiated. > > Hmmm, but I want the settings to be in my settings module to be forward > compatible with Django 1.3. That means I have to be initializing *after* the > settings are loaded. Django 1.3 does this in the Settings() class __init__. > I'm not clear on when the user switch is made, but, if the Django 1.3 > approach works, the actual Settings() class must be instantiated after the > user switch. > >> I usually write a separate module with my logging code in it and call >> it in the WSGI hook file. I also found that using the logging config >> file mechanism didn't work correctly, so dynamically set up logging. > > See above. The whole idea is to be Django 1.3 compatible by just removing my > hand-initialization of logging and letting Django's Settings() init do it. > >> Also don't put the logs in the /var/log path as root or adm are usually the >> only users that can write to it. > > I temporarily changed the permissions to let www-data write to it; the > problem is that the file is created as root if I initialize the logging in > settings.py. > > I'm not sure at what point the "current user" is switched to www-data so that > creating the log will happen as that user. > >> In production we use an NFS mount for all logs and in testing I put the logs >> in the Django >> project environment. If you are using daemon mode with mod_wsgi the logs >> will be written out with that user so your files need to all be set to that >> user also. > > The www-data user is trying to write the logs, but they've been created by > root and are not writable. > > So, is there a safe place to initialize logging after the user switch has > been made? > > I'll move the log files to someplace outside /var/log that's owned by the > right user, too, but I've got to get them created *after* settings are loaded > and *after* the user switch is done. > > Thanks! > > S > > > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/modwsgi?hl=en. > > -- ------------------------------------------------------------------------------- Carl J. Nobile (Software Engineer) [email protected] ------------------------------------------------------------------------------- -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
