File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ def _setup():
2323 else :
2424 logging_config = {}
2525
26+ file_log = logging_config .get ("file_log" , False )
27+
2628 global logging_dir
2729 logging_dir = os .path .join (os .path .abspath (os .path .curdir ), "logs" )
2830
@@ -49,25 +51,29 @@ def _setup():
4951 "formatter" : "brief" ,
5052 "level" : "INFO" ,
5153 "stream" : "ext://sys.stdout"
52- },
53- "file" : {
54- "class" : "logging.handlers.RotatingFileHandler" ,
55- "maxBytes" : 1000000 ,
56- "backupCount" : 5 ,
57- "formatter" : "full" ,
58- "level" : "INFO" ,
59- "encoding" : "utf-8" ,
60- "filename" : os .path .join (logging_dir , "bot.log" )
6154 }
6255 },
6356 "loggers" : {
6457 "cloudbot" : {
6558 "level" : "DEBUG" ,
66- "handlers" : ["console" , "file" ]
59+ "handlers" : ["console" ]
6760 }
6861 }
6962 }
7063
64+ if file_log :
65+ dict_config ["handlers" ]["file" ] = {
66+ "class" : "logging.handlers.RotatingFileHandler" ,
67+ "maxBytes" : 1000000 ,
68+ "backupCount" : 5 ,
69+ "formatter" : "full" ,
70+ "level" : "INFO" ,
71+ "encoding" : "utf-8" ,
72+ "filename" : os .path .join (logging_dir , "bot.log" )
73+ }
74+
75+ dict_config ["loggers" ]["cloudbot" ]["handlers" ].append ("file" )
76+
7177 if logging_config .get ("console_debug" , False ):
7278 dict_config ["handlers" ]["console" ]["level" ] = "DEBUG"
7379 dict_config ["loggers" ]["asyncio" ] = {
@@ -89,4 +95,5 @@ def _setup():
8995
9096 logging .config .dictConfig (dict_config )
9197
98+
9299_setup ()
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 99# +---------+
1010# | Formats |
1111# +---------+
12- from cloudbot .hook import Priority
1312from cloudbot .util .formatting import strip_colors
1413
1514base_formats = {
@@ -127,6 +126,7 @@ def format_irc_event(event, args):
127126
128127 return irc_default .format (server = event .conn .name , irc_raw = event .irc_raw )
129128
129+
130130# +--------------+
131131# | File logging |
132132# +--------------+
@@ -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