forked from Ji3jin/sqlpro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
104 lines (83 loc) · 2.93 KB
/
config.py
File metadata and controls
104 lines (83 loc) · 2.93 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
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File : config.py
# Author: jixin
# Date : 18-10-17
import os
import uuid
import logging
basedir = os.path.abspath(os.path.dirname(__file__))
class InfoFilter(logging.Filter):
def filter(self, record):
"""only use INFO
筛选, 只需要 INFO 级别的log
:param record:
:return:
"""
if logging.INFO <= record.levelno < logging.ERROR:
# 已经是INFO级别了
# 然后利用父类, 返回 1
return super().filter(record)
else:
return 0
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY') or str(uuid.uuid4())
SSL_DISABLE = False
SQLALCHEMY_RECORD_QUERIES = True
LOG_PATH = os.path.join(basedir, 'logs')
LOG_PATH_ERROR = os.path.join(LOG_PATH, 'error.log')
LOG_PATH_INFO = os.path.join(LOG_PATH, 'info.log')
LOG_FILE_MAX_BYTES = 5 * 1024 * 1024
LOG_FILE_BACKUP_COUNT = 5
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/1'
@staticmethod
def init_app(app):
pass
class DevConfig(Config):
DEBUG = True
PRESERVE_CONTEXT_ON_EXCEPTION = False
WTF_CSRF_ENABLED = False
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:123456@127.0.0.1:3306/sqlprotest"
PRESTO_URI = "presto://localhost:8989"
PRESTO_HTTP_URI = "http://localhost:8989"
REDIS_HOST = "localhost"
REDIS_PORT = 6379
SQLALCHEMY_TRACK_MODIFICATIONS = True
@classmethod
def init_app(cls, app):
Config.init_app(app)
import logging
from logging.handlers import SysLogHandler
syslog_handler = SysLogHandler()
syslog_handler.setLevel(logging.WARNING)
app.logger.addHandler(syslog_handler)
class ProConfig(Config):
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:123456@127.0.0.1:3306/sqlpro"
PRESTO_URI = "presto://localhost:8989"
PRESTO_HTTP_URI = "http://localhost:8989"
REDIS_HOST = "localhost"
REDIS_PORT = 6379
@classmethod
def init_app(cls, app):
Config.init_app(app)
import logging
from logging.handlers import RotatingFileHandler
formatter = logging.Formatter(
'%(asctime)s %(levelname)s %(process)d %(thread)d '
'%(pathname)s %(lineno)s %(message)s')
file_handler_info = RotatingFileHandler(filename=cls.LOG_PATH_INFO)
file_handler_info.setFormatter(formatter)
file_handler_info.setLevel(logging.INFO)
info_filter = InfoFilter()
file_handler_info.addFilter(info_filter)
app.logger.addHandler(file_handler_info)
file_handler_error = RotatingFileHandler(filename=cls.LOG_PATH_ERROR)
file_handler_error.setFormatter(formatter)
file_handler_error.setLevel(logging.ERROR)
app.logger.addHandler(file_handler_error)
config = {
'development': DevConfig,
'production': ProConfig,
'default': DevConfig
}