1 | # Django settings for logtest project.
|
---|
2 |
|
---|
3 | DEBUG = True
|
---|
4 | TEMPLATE_DEBUG = DEBUG
|
---|
5 |
|
---|
6 | ADMINS = (
|
---|
7 | # ('Your Name', 'your_email@domain.com'),
|
---|
8 | )
|
---|
9 |
|
---|
10 | MANAGERS = ADMINS
|
---|
11 |
|
---|
12 | #DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
---|
13 | #DATABASE_NAME = 'logtest.db' # Or path to database file if using sqlite3.
|
---|
14 | DATABASE_ENGINE = 'postgresql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
---|
15 | DATABASE_NAME = 'mathprob' # Or path to database file if using sqlite3.
|
---|
16 | DATABASE_USER = 'mathprob' # Not used with sqlite3.
|
---|
17 | DATABASE_PASSWORD = 'm4thpr0b' # Not used with sqlite3.
|
---|
18 | DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
---|
19 | DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
|
---|
20 |
|
---|
21 | # Local time zone for this installation. Choices can be found here:
|
---|
22 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
---|
23 | # although not all choices may be available on all operating systems.
|
---|
24 | # If running in a Windows environment this must be set to the same as your
|
---|
25 | # system time zone.
|
---|
26 | TIME_ZONE = 'Europe/London'
|
---|
27 |
|
---|
28 | # Language code for this installation. All choices can be found here:
|
---|
29 | # http://www.i18nguy.com/unicode/language-identifiers.html
|
---|
30 | LANGUAGE_CODE = 'en-gb'
|
---|
31 |
|
---|
32 | SITE_ID = 1
|
---|
33 |
|
---|
34 | # If you set this to False, Django will make some optimizations so as not
|
---|
35 | # to load the internationalization machinery.
|
---|
36 | USE_I18N = True
|
---|
37 |
|
---|
38 | # Absolute path to the directory that holds media.
|
---|
39 | # Example: "/home/media/media.lawrence.com/"
|
---|
40 | MEDIA_ROOT = ''
|
---|
41 |
|
---|
42 | # URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
---|
43 | # trailing slash if there is a path component (optional in other cases).
|
---|
44 | # Examples: "http://media.lawrence.com", "http://example.com/media/"
|
---|
45 | MEDIA_URL = ''
|
---|
46 |
|
---|
47 | # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
|
---|
48 | # trailing slash.
|
---|
49 | # Examples: "http://foo.com/media/", "/media/".
|
---|
50 | ADMIN_MEDIA_PREFIX = '/media/'
|
---|
51 |
|
---|
52 | # Make this unique, and don't share it with anybody.
|
---|
53 | SECRET_KEY = '5pl!d=!iany87jxjkg8cycrkbsvr0dph4^wtp^dh4b6*3le-w='
|
---|
54 |
|
---|
55 | # List of callables that know how to import templates from various sources.
|
---|
56 | TEMPLATE_LOADERS = (
|
---|
57 | 'django.template.loaders.filesystem.load_template_source',
|
---|
58 | 'django.template.loaders.app_directories.load_template_source',
|
---|
59 | # 'django.template.loaders.eggs.load_template_source',
|
---|
60 | )
|
---|
61 |
|
---|
62 | MIDDLEWARE_CLASSES = (
|
---|
63 | 'django.middleware.common.CommonMiddleware',
|
---|
64 | 'django.contrib.sessions.middleware.SessionMiddleware',
|
---|
65 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
|
---|
66 | )
|
---|
67 |
|
---|
68 | ROOT_URLCONF = 'logtest.urls'
|
---|
69 |
|
---|
70 | TEMPLATE_DIRS = (
|
---|
71 | # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
---|
72 | # Always use forward slashes, even on Windows.
|
---|
73 | # Don't forget to use absolute paths, not relative paths.
|
---|
74 | )
|
---|
75 |
|
---|
76 | INSTALLED_APPS = (
|
---|
77 | 'django.contrib.auth',
|
---|
78 | 'django.contrib.contenttypes',
|
---|
79 | 'django.contrib.sessions',
|
---|
80 | 'django.contrib.sites',
|
---|
81 | )
|
---|
82 |
|
---|
83 | import logging
|
---|
84 |
|
---|
85 | def init_logging():
|
---|
86 | #Configure root to write to file
|
---|
87 | logging.basicConfig(level=logging.DEBUG, filename='logtest.log',
|
---|
88 | filemode='w', format='%(asctime)s %(levelname)-8s %(name)-13s %(message)s')
|
---|
89 | logger = logging.getLogger("logtest")
|
---|
90 | logger.setLevel(logging.INFO)
|
---|
91 | logger = logging.getLogger("logtest.foo")
|
---|
92 | logger.setLevel(logging.WARNING)
|
---|
93 | logger = logging.getLogger("logtest.bar")
|
---|
94 | logger.setLevel(logging.ERROR)
|
---|
95 |
|
---|
96 | def test_logging():
|
---|
97 | from random import choice
|
---|
98 | levels = (logging.DEBUG, logging.INFO, logging.WARNING,
|
---|
99 | logging.ERROR, logging.CRITICAL)
|
---|
100 | loggers = ('', 'logtest', 'logtest.foo', 'logtest.bar')
|
---|
101 | for i in xrange(1000):
|
---|
102 | level = choice(levels)
|
---|
103 | logger = logging.getLogger(choice(loggers))
|
---|
104 | logger.log(level, "Message #%d", i + 1)
|
---|
105 |
|
---|
106 |
|
---|
107 | def listener(sender, *args, **kwargs):
|
---|
108 | logger = logging.getLogger("logtest")
|
---|
109 | logger.info("class_prepared listener called: %s", sender.__name__)
|
---|
110 |
|
---|
111 | def pre_model_callback():
|
---|
112 | from django.db.models.signals import class_prepared
|
---|
113 | logger = logging.getLogger("logtest")
|
---|
114 | logger.info("Adding listener for class_prepared...")
|
---|
115 | class_prepared.connect(listener)
|
---|
116 |
|
---|
117 | def post_model_callback():
|
---|
118 | from django.contrib.auth.models import User
|
---|
119 | logger = logging.getLogger("logtest")
|
---|
120 | try:
|
---|
121 | logger.info("ORM works: all users: %s" % ", ".join(["%(username)s (%(first_name)s %(last_name)s)" % u.__dict__ for u in User.objects.all()]))
|
---|
122 | except:
|
---|
123 | logger.exception("Unable to get all users")
|
---|
124 |
|
---|
125 | BOOTSTRAP_CALLBACKS = (
|
---|
126 | init_logging,
|
---|
127 | #test_logging,
|
---|
128 | )
|
---|
129 |
|
---|
130 | PRE_MODEL_CALLBACKS = (
|
---|
131 | pre_model_callback,
|
---|
132 | )
|
---|
133 |
|
---|
134 | POST_MODEL_CALLBACKS = (
|
---|
135 | post_model_callback,
|
---|
136 | )
|
---|