22
33# check python version
44if sys .version_info < (3 , 4 , 0 ):
5- print ("CloudBot3 requires Python 3.4 or newer." )
5+ print ("CloudBot requires Python 3.4 or newer." )
66 sys .exit (1 )
77
88import json
1212
1313__version__ = "0.1.1.dev0"
1414
15- __all__ = ["util" , "bot" , "connection" , "config" , "permissions" , "plugin" , "event" , "hook" , "dev_mode" , " log_dir" ]
15+ __all__ = ["util" , "bot" , "connection" , "config" , "permissions" , "plugin" , "event" , "hook" , "log_dir" ]
1616
1717
1818def _setup ():
19- default_developer_mode = {"plugin_reloading" : False , "config_reloading" : True ,
20- "console_debug" : False , "file_debug" : True }
2119 if os .path .exists (os .path .abspath ("config.json" )):
2220 with open (os .path .abspath ("config.json" )) as config_file :
2321 json_conf = json .load (config_file )
24- developer_mode = json_conf .get ("developer_mode " , default_developer_mode )
22+ logging_config = json_conf .get ("logging " , {} )
2523 else :
26- developer_mode = default_developer_mode
24+ logging_config = {}
2725
28- if "config_reloading" not in developer_mode :
29- developer_mode ["config_reloading" ] = default_developer_mode ["config_reloading" ]
30- if "plugin_reloading" not in developer_mode :
31- developer_mode ["plugin_reloading" ] = default_developer_mode ["plugin_reloading" ]
32- if "console_debug" not in developer_mode :
33- developer_mode ["console_debug" ] = default_developer_mode ["console_debug" ]
34- if "file_debug" not in developer_mode :
35- developer_mode ["file_debug" ] = default_developer_mode ["file_debug" ]
26+ console_debug = logging_config .get ("console_debug" , False )
27+ file_debug = logging_config .get ("file_debug" , True )
3628
37- global log_dir
38- log_dir = os .path .join (os .path .abspath (os .path .curdir ), "logs" )
29+ global logging_dir
30+ logging_dir = os .path .join (os .path .abspath (os .path .curdir ), "logs" )
3931
40- if not os .path .exists (log_dir ):
41- os .makedirs (log_dir )
32+ if not os .path .exists (logging_dir ):
33+ os .makedirs (logging_dir )
4234
4335 dict_config = {
4436 "version" : 1 ,
@@ -66,7 +58,7 @@ def _setup():
6658 "formatter" : "full" ,
6759 "level" : "INFO" ,
6860 "encoding" : "utf-8" ,
69- "filename" : os .path .join (log_dir , "bot.log" )
61+ "filename" : os .path .join (logging_dir , "bot.log" )
7062 }
7163 },
7264 "loggers" : {
@@ -77,24 +69,21 @@ def _setup():
7769 }
7870 }
7971
80- if developer_mode [ " console_debug" ] :
72+ if console_debug :
8173 dict_config ["handlers" ]["console" ]["level" ] = "DEBUG"
8274
83- if developer_mode [ " file_debug" ] :
75+ if file_debug :
8476 dict_config ["handlers" ]["debug_file" ] = {
8577 "class" : "logging.handlers.RotatingFileHandler" ,
8678 "maxBytes" : 1000000 ,
8779 "backupCount" : 5 ,
8880 "formatter" : "full" ,
8981 "encoding" : "utf-8" ,
9082 "level" : "DEBUG" ,
91- "filename" : os .path .join (log_dir , "debug.log" )
83+ "filename" : os .path .join (logging_dir , "debug.log" )
9284 }
9385 dict_config ["loggers" ]["cloudbot" ]["handlers" ].append ("debug_file" )
9486
9587 logging .config .dictConfig (dict_config )
9688
97- return developer_mode
98-
99-
100- dev_mode = _setup ()
89+ _setup ()
0 commit comments