-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaitress_config.py
More file actions
43 lines (29 loc) · 1.12 KB
/
waitress_config.py
File metadata and controls
43 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import logging
from waitress import serve
bind = '127.0.0.1:8000'
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
log_file = os.path.join(BASE_DIR, 'waitress_server.log')
logging.basicConfig(filename=log_file, level=logging.INFO,
format='%(asctime)s %(levelname)s: %(message)s')
def setup_server():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dvs.settings')
from django.core.wsgi import get_wsgi_application
logging.info('Waitress server started')
return get_wsgi_application()
if os.name == 'nt':
import sys
class WindowsLoggingHandler(logging.Handler):
def emit(self, record):
msg = self.format(record)
sys.stdout.write(msg + '\n')
logger = logging.getLogger('')
logger.setLevel(logging.INFO)
handler = WindowsLoggingHandler()
formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
if __name__ == '__main__':
application = setup_server()
serve(application, listen=bind)