-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
98 lines (85 loc) · 2.59 KB
/
config.py
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
import os
import sys
from loguru import logger
from dynaconf import Dynaconf
global_config = Dynaconf(
load_dotenv=True,
envvar_prefix=False,
settings_files=['config/settings.json', 'config/.secrets.json'],
)
config = (
global_config.production
if global_config.potionx_env == "production" else
global_config.development
)
# log-config
class PLog:
""" 自定义的日志配置
"""
log_format = (
"<level>{level: <8}</level> "
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> - "
"<blue>{process}</blue> "
"<cyan>{module}</cyan>.<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
"<level>{message}</level>"
)
def __init__(self):
logger.remove()
self._log_path = "logs"
os.makedirs(self._log_path, exist_ok=True)
self._init_stdout_log()
self._init_debug_log()
self._init_info_log()
self._init_error_log()
def _init_info_log(self):
logger.add(
os.path.join(self._log_path, "info.log.{time:YYYY-MM-DD}"),
format=self.log_format,
level="INFO",
rotation="00:00",
retention="3 days",
backtrace=True,
diagnose=True,
)
def _init_error_log(self):
logger.add(
os.path.join(self._log_path, "error.log.{time:YYYY-MM-DD}"),
format=self.log_format,
level="ERROR",
rotation="00:00",
retention="3 days",
backtrace=True,
diagnose=True,
)
def _init_debug_log(self):
logger.add(
os.path.join(self._log_path, "debug.log.{time:YYYY-MM-DD}"),
format=self.log_format,
level="DEBUG",
rotation="00:00",
retention="1 days",
backtrace=True,
diagnose=True,
)
def _init_stdout_log(self):
logger.add(
sys.stdout,
format=self.log_format,
level="INFO",
colorize=True,
)
print(
"""
\ | | /
| Ø___oo
/ \ / \ / (__ „ „ „ „]
/ ^ \ / ^ \ / _)
) V V V / __)
) / / ___)
/ \ V¯V¯V| | )__)
< > / ( „ „ ) ) ___)
| | ( | \_ ___)\_
| \______( / )____)_)_
\____________(______;_;_)_;_;_)ƨ -byacaicai
"""
)