1
+ import json
2
+ import logging
3
+ import logging .config
4
+ import os
1
5
import sys
2
6
3
7
# check python version
4
8
if sys .version_info < (3 , 5 , 3 ):
5
9
print ("CloudBot requires Python 3.5.3 or newer." )
6
10
sys .exit (1 )
7
11
8
- import json
9
- import logging .config
10
- import logging
11
- import os
12
12
13
13
version = (1 , 3 , 0 )
14
- __version__ = '.' .join (str (i ) for i in version )
14
+ __version__ = "." .join (str (i ) for i in version )
15
15
16
16
__all__ = (
17
17
"clients" ,
@@ -52,40 +52,41 @@ def _setup():
52
52
logging_config = {}
53
53
54
54
file_log = logging_config .get ("file_log" , False )
55
- console_level = "INFO" if logging_config .get ("console_log_info" , True ) else "WARNING"
55
+ console_level = (
56
+ "INFO" if logging_config .get ("console_log_info" , True ) else "WARNING"
57
+ )
56
58
57
59
logging_info .dir = os .path .join (os .path .abspath (os .path .curdir ), "logs" )
58
60
59
61
logging_info .make_dir ()
60
62
61
63
logging .captureWarnings (True )
62
64
65
+ logger_names = ["cloudbot" , "plugins" ]
66
+
63
67
dict_config = {
64
68
"version" : 1 ,
65
69
"formatters" : {
66
70
"brief" : {
67
71
"format" : "[%(asctime)s] [%(levelname)s] %(message)s" ,
68
- "datefmt" : "%H:%M:%S"
72
+ "datefmt" : "%H:%M:%S" ,
69
73
},
70
74
"full" : {
71
75
"format" : "[%(asctime)s] [%(levelname)s] %(message)s" ,
72
- "datefmt" : "%Y-%m-%d][%H:%M:%S"
73
- }
76
+ "datefmt" : "%Y-%m-%d][%H:%M:%S" ,
77
+ },
74
78
},
75
79
"handlers" : {
76
80
"console" : {
77
81
"class" : "logging.StreamHandler" ,
78
82
"formatter" : "brief" ,
79
83
"level" : console_level ,
80
- "stream" : "ext://sys.stdout"
84
+ "stream" : "ext://sys.stdout" ,
81
85
}
82
86
},
83
87
"loggers" : {
84
- "cloudbot" : {
85
- "level" : "DEBUG" ,
86
- "handlers" : ["console" ]
87
- }
88
- }
88
+ name : {"level" : "DEBUG" , "handlers" : ["console" ]} for name in logger_names
89
+ },
89
90
}
90
91
91
92
if file_log :
@@ -96,17 +97,15 @@ def _setup():
96
97
"formatter" : "full" ,
97
98
"level" : "INFO" ,
98
99
"encoding" : "utf-8" ,
99
- "filename" : logging_info .add_path ("bot.log" )
100
+ "filename" : logging_info .add_path ("bot.log" ),
100
101
}
101
102
102
- dict_config ["loggers" ]["cloudbot" ]["handlers" ].append ("file" )
103
+ for name in logger_names :
104
+ dict_config ["loggers" ][name ]["handlers" ].append ("file" )
103
105
104
106
if logging_config .get ("console_debug" , False ):
105
107
dict_config ["handlers" ]["console" ]["level" ] = "DEBUG"
106
- dict_config ["loggers" ]["asyncio" ] = {
107
- "level" : "DEBUG" ,
108
- "handlers" : ["console" ]
109
- }
108
+ dict_config ["loggers" ]["asyncio" ] = {"level" : "DEBUG" , "handlers" : ["console" ]}
110
109
if file_log :
111
110
dict_config ["loggers" ]["asyncio" ]["handlers" ].append ("file" )
112
111
@@ -118,9 +117,10 @@ def _setup():
118
117
"formatter" : "full" ,
119
118
"encoding" : "utf-8" ,
120
119
"level" : "DEBUG" ,
121
- "filename" : logging_info .add_path ("debug.log" )
120
+ "filename" : logging_info .add_path ("debug.log" ),
122
121
}
123
- dict_config ["loggers" ]["cloudbot" ]["handlers" ].append ("debug_file" )
122
+ for name in logger_names :
123
+ dict_config ["loggers" ][name ]["handlers" ].append ("debug_file" )
124
124
125
125
logging .config .dictConfig (dict_config )
126
126
0 commit comments