-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
91 lines (84 loc) · 2.82 KB
/
app.py
File metadata and controls
91 lines (84 loc) · 2.82 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
import logging
import os
from logging.config import dictConfig
import connexion
from environs import Env
from flask_cors import CORS
from settings import set_ext_logger, LOG_DATE_FORMAT, ERROR_FILE_PATH, LOG_FILE_PATH, DEBUG_FILE_PATH, APP_NAME
from swagger_server import encoder
SERVICE_ENVIRONMENT = os.getenv("SERVICE_ENVIRONMENT", "development")
debug = True
if SERVICE_ENVIRONMENT == 'production':
debug = False
dictConfig({
'version': 1,
'formatters': {
'default': {
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
'datefmt': LOG_DATE_FORMAT,
},
'simple': {
'format': '%(asctime)s %(levelname)s in %(name)s: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
'info': {
'format': '[%(asctime)s] %(levelname)s in %(name)s::%(module)s|%(lineno)s:: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
'error': {
'format': '[%(asctime)s] %(levelname)s in %(name)s %(process)d::%(module)s|%(lineno)s:: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
},
'handlers': {
'wsgi': {
'class': 'logging.StreamHandler',
'stream': 'ext://flask.logging.wsgi_errors_stream',
'formatter': 'default',
'level': logging.INFO,
},
'error_file_handler': {
'class': 'logging.FileHandler',
'formatter': 'error',
'filename': ERROR_FILE_PATH,
'level': logging.WARN,
'mode': 'a',
'encoding': 'utf-8',
},
'info_rotating_file_handler': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'info',
'level': logging.INFO,
'filename': LOG_FILE_PATH,
'mode': 'a',
'encoding': 'utf-8',
'maxBytes': 500000,
'backupCount': 10
},
'debug_rotating_file_handler': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'error',
'level': logging.DEBUG,
'filename': DEBUG_FILE_PATH,
'mode': 'a',
'encoding': 'utf-8',
'maxBytes': 1000000,
'backupCount': 10
},
},
'root': {
'level': 'INFO',
'handlers': ['wsgi', 'info_rotating_file_handler', 'error_file_handler', 'debug_rotating_file_handler']
},
})
app = connexion.App(__name__, specification_dir='swagger_server/swagger/')
app.app.json_encoder = encoder.JSONEncoder
app.app.logger.info("The logger configured!")
set_ext_logger(app.app.logger)
app.add_api('swagger.yaml', arguments={'title': APP_NAME}, pythonic_params=True)
CORS(app.app)
env = Env()
env.read_env()
if __name__ == '__main__':
app.run(port=8080, debug=debug)