Skip to content

Commit 2b2f510

Browse files
committed
Add config option to disable all log files
1 parent 8857dc7 commit 2b2f510

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

cloudbot/__init__.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff 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()

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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# +---------+
1010
# | Formats |
1111
# +---------+
12-
from cloudbot.hook import Priority
1312
from cloudbot.util.formatting import strip_colors
1413

1514
base_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:

0 commit comments

Comments
 (0)