Permalink
Browse files

pulling in support for settings_local.py

  • Loading branch information...
1 parent e6b201f commit 6fe3c3b7a1d8e58c8199b59651cd8389e2d071a5 James Socol committed Feb 3, 2010
Showing with 48 additions and 5 deletions.
  1. +27 −0 log_settings.py
  2. +21 −5 manage.py
View
@@ -0,0 +1,27 @@
+import logging
+import logging.handlers
+
+from django.conf import settings
+
+
+# Loggers created under the "z" namespace, e.g. "z.caching", will inherit the
+# configuration from the base z logger.
+log = logging.getLogger('dj')
+
+fmt = '%(asctime)s %(name)s:%(levelname)s %(message)s :%(pathname)s:%(lineno)s'
+fmt = getattr(settings, 'LOG_FORMAT', fmt)
+level = settings.LOG_LEVEL
+
+if settings.DEBUG:
+ handler = logging.StreamHandler()
+ formatter = logging.Formatter(fmt, datefmt='%H:%M:%S')
+else:
+ SysLogger = logging.handlers.SysLogHandler
+ handler = SysLogger(facility=SysLogger.LOG_LOCAL7)
+ formatter = logging.Formatter(fmt)
+
+log.setLevel(level)
+handler.setLevel(level)
+handler.setFormatter(formatter)
+log.addHandler(handler)
+
View
@@ -1,11 +1,27 @@
#!/usr/bin/env python
-from django.core.management import execute_manager
+import site
+from django.core.management import execute_manager, setup_environ
+
try:
- import settings # Assumed to be in the same directory.
+ import settings_local as settings
except ImportError:
- import sys
- sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
- sys.exit(1)
+ try:
+ import settings # Assumed to be in the same directory.
+ except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+ sys.exit(1)
+
+site.addsitedir(settings.path('apps'))
+site.addsitedir(settings.path('lib'))
+
+# The first thing execute_manager does is call `setup_environ`. Logging config
+# needs to access settings, so we'll setup the environ early.
+setup_environ(settings)
+
+# Import for side-effect: configures our logging handlers.
+import log_settings
+
if __name__ == "__main__":
execute_manager(settings)

0 comments on commit 6fe3c3b

Please sign in to comment.