Skip to content

Commit cbdaf9f

Browse files
authored
Merge pull request CloudBotIRC#131 from linuxdaemon/gonzobot+file-log-config
Add config option to disable all log files
2 parents 73781e1 + 39ec8c5 commit cbdaf9f

3 files changed

Lines changed: 22 additions & 11 deletions

File tree

cloudbot/__init__.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff 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"] = {

config.default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
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
}

plugins/log.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)