File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ def _setup():
2424 else :
2525 logging_config = {}
2626
27+ file_log = logging_config .get ("file_log" , False )
28+
2729 global logging_dir
2830 logging_dir = os .path .join (os .path .abspath (os .path .curdir ), "logs" )
2931
@@ -50,25 +52,29 @@ def _setup():
5052 "formatter" : "brief" ,
5153 "level" : "INFO" ,
5254 "stream" : "ext://sys.stdout"
53- },
54- "file" : {
55- "class" : "logging.handlers.RotatingFileHandler" ,
56- "maxBytes" : 1000000 ,
57- "backupCount" : 5 ,
58- "formatter" : "full" ,
59- "level" : "INFO" ,
60- "encoding" : "utf-8" ,
61- "filename" : os .path .join (logging_dir , "bot.log" )
6255 }
6356 },
6457 "loggers" : {
6558 "cloudbot" : {
6659 "level" : "DEBUG" ,
67- "handlers" : ["console" , "file" ]
60+ "handlers" : ["console" ]
6861 }
6962 }
7063 }
7164
65+ if file_log :
66+ dict_config ["handlers" ]["file" ] = {
67+ "class" : "logging.handlers.RotatingFileHandler" ,
68+ "maxBytes" : 1000000 ,
69+ "backupCount" : 5 ,
70+ "formatter" : "full" ,
71+ "level" : "INFO" ,
72+ "encoding" : "utf-8" ,
73+ "filename" : os .path .join (logging_dir , "bot.log" )
74+ }
75+
76+ dict_config ["loggers" ]["cloudbot" ]["handlers" ].append ("file" )
77+
7278 if logging_config .get ("console_debug" , False ):
7379 dict_config ["handlers" ]["console" ]["level" ] = "DEBUG"
7480 dict_config ["loggers" ]["asyncio" ] = {
Original file line number Diff line number Diff line change 120120 "show_plugin_loading" : true ,
121121 "show_motd" : true ,
122122 "show_server_info" : true ,
123- "raw_file_log" : false
123+ "raw_file_log" : false ,
124+ "file_log" : true
124125 }
125126}
Original file line number Diff line number Diff line change @@ -219,6 +219,10 @@ def log(event):
219219 """
220220 :type event: cloudbot.event.Event
221221 """
222+ logging_config = event .bot .config .get ("logging" , {})
223+ if not logging_config .get ("file_log" , False ):
224+ return
225+
222226 text = format_event (event )
223227
224228 if text is not None :
You can’t perform that action at this time.
0 commit comments