8000 Add settings for production · python-doc-tw/pydoc_autobuild@2842ade · GitHub
[go: up one dir, main page]

Skip to content

Commit 2842ade

Browse files
committed
Add settings for production
1 parent 208693d commit 2842ade

File tree

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# In production set the environment variable like this:
2+
# DJANGO_SETTINGS_MODULE=my_proj.settings.production
3+
from .base import * # NOQA
4+
import logging.config
5+
6+
# For security and performance reasons, DEBUG is turned off
7+
DEBUG = False
8+
9+
# Must mention ALLOWED_HOSTS in production!
10+
ALLOWED_HOSTS = ['pydoc.liang2.tw']
11+
12+
13+
# Cache the templates in memory for speed-up
14+
loaders = [
15+
(
16+
'django.template.loaders.cached.Loader',
17+
[
18+
'django.template.loaders.filesystem.Loader',
19+
'django.template.loaders.app_directories.Loader',
20+
]
21+
),
22+
]
23+
24+
TEMPLATES[0]['OPTIONS'].update({"loaders": loaders})
25+
TEMPLATES[0]['OPTIONS'].update({"debug": False})
26+
del TEMPLATES[0]['APP_DIRS']
27+
28+
# Explicitly tell Django where to find translations.
29+
LOCALE_PATHS = [join(BASE_DIR, 'locale')]
30+
31+
# Log everything to the logs directory at the top
32+
LOGFILE_ROOT = join(dirname(BASE_DIR), 'logs')
33+
34+
# Reset logging
35+
LOGGING_CONFIG = None
36+
LOGGING = {
37+
'version': 1,
38+
'disable_existing_loggers': False,
39+
'formatters': {
40+
'verbose': {
41+
'format': (
42+
'[%(asctime)s] %(levelname)s '
43+
'[%(pathname)s:%(lineno)s] %(message)s'
44+
),
45+
'datefmt': "%d/%b/%Y %H:%M:%S"
46+
},
47+
'simple': {
48+
'format': '%(levelname)s %(message)s'
49+
},
50+
},
51+
'handlers': {
52+
'proj_log_file': {
53+
'level': 'DEBUG',
54+
'class': 'logging.FileHandler',
55+
'filename': join(LOGFILE_ROOT, 'project.log'),
56+
'formatter': 'verbose'
57+
},
58+
'django_log_file': {
59+
'level': 'DEBUG',
60+
'class': 'logging.FileHandler',
61+
'filename': join(LOGFILE_ROOT, 'django.log'),
62+
'formatter': 'verbose'
63+
},
64+
'console': {
65+
'level': 'DEBUG',
66+
'class': 'logging.StreamHandler',
67+
'formatter': 'simple'
68+
}
69+
},
70+
'loggers': {
71+
'django': {
72+
'handlers': ['django_log_file'],
73+
'propagate': True,
74+
'level': 'DEBUG',
75+
},
76+
'project': {
77+
'handlers': ['proj_log_file'],
78+
'level': 'DEBUG',
79+
},
80+
}
81+
}
82+
83+
logging.config.dictConfig(LOGGING)

0 commit comments

Comments
 (0)
0