File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ import copy
2
+ import datetime
1
3
import os
2
4
3
5
from flask import current_app
@@ -13,3 +15,30 @@ def plugin_available(plugin_name: str) -> bool:
13
15
return mode .lower () in current_app .config [f"{ plugin_name .upper ()} _AVAILABLE_IN" ]
14
16
else :
15
17
raise EnvironmentError ("MODE not in environment variables" )
18
+
19
+
20
+ __load_time = datetime .datetime .now ()
21
+
22
+
23
+ def print_config (app , logger ):
24
+ """启动时输出当前配置项"""
25
+ # 如果当前时间与模块加载时间相差一分钟之内,认为是第一次 spawn(进程随着时间的推移可能会被 uwsgi 回收),
26
+ # 在 1 号 worker 里打印当前配置
27
+ import uwsgi
28
+ if uwsgi .worker_id () == 1 and (datetime .datetime .now () - __load_time ) < datetime .timedelta (minutes = 1 ):
29
+ # 这里设置等级为 warning 因为我们希望在 sentry 里监控重启情况
30
+ logger .warning (f'App (re)started in `{ app .config ["CONFIG_NAME" ]} ` environment' )
31
+
32
+ logger .info ('Below are configurations we are using:' )
33
+ logger .info ('================================================================' )
34
+ for key , value in app .config .items ():
35
+ if key not in app .config .PRODUCTION_SECURE_FIELDS :
36
+ if any (map (lambda t : isinstance (value , t ), (dict ,))):
37
+ value = copy .copy (value )
38
+ for k in value .keys ():
39
+ if "{}.{}" .format (key , k ) in app .config .PRODUCTION_SECURE_FIELDS :
40
+ value [k ] = '[secret]'
41
+ logger .info ('{}: {}' .format (key , value ))
42
+ else :
43
+ logger .info ("{}: [secret]" .format (key ))
44
+ logger .info ('================================================================' )
You can’t perform that action at this time.
0 commit comments