aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-11-20 23:04:01 +0300
committerGravatar Hassan Abouelela <[email protected]>2021-11-20 23:07:58 +0300
commitd14a15886301ba660564bfd80480d46d5a435e65 (patch)
treedaba8ae9ec2838478a641daf4238824e1d9ad4c6
parentMerge pull request #1965 from python-discord/ChrisLovering-patch-1 (diff)
Disable File Logging By Default
Place logging to file behind an environment variable, and remove special considerations made for it. Signed-off-by: Hassan Abouelela <[email protected]>
-rw-r--r--bot/constants.py1
-rw-r--r--bot/log.py15
-rw-r--r--config-default.yml3
-rw-r--r--docker-compose.yml1
4 files changed, 11 insertions, 9 deletions
diff --git a/bot/constants.py b/bot/constants.py
index 2dfdd51e2..36b917734 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -685,6 +685,7 @@ class VideoPermission(metaclass=YAMLGetter):
# Debug mode
DEBUG_MODE: bool = _CONFIG_YAML["debug"] == "true"
+FILE_LOGS: bool = _CONFIG_YAML["file_logs"].lower() == "true"
# Paths
BOT_DIR = os.path.dirname(__file__)
diff --git a/bot/log.py b/bot/log.py
index b3cecdcf2..100cd06f6 100644
--- a/bot/log.py
+++ b/bot/log.py
@@ -48,16 +48,17 @@ def setup() -> None:
logging.addLevelName(TRACE_LEVEL, "TRACE")
logging.setLoggerClass(CustomLogger)
+ root_log = get_logger()
+
format_string = "%(asctime)s | %(name)s | %(levelname)s | %(message)s"
log_format = logging.Formatter(format_string)
- log_file = Path("logs", "bot.log")
- log_file.parent.mkdir(exist_ok=True)
- file_handler = handlers.RotatingFileHandler(log_file, maxBytes=5242880, backupCount=7, encoding="utf8")
- file_handler.setFormatter(log_format)
-
- root_log = get_logger()
- root_log.addHandler(file_handler)
+ if constants.FILE_LOGS:
+ log_file = Path("logs", "bot.log")
+ log_file.parent.mkdir(exist_ok=True)
+ file_handler = handlers.RotatingFileHandler(log_file, maxBytes=5242880, backupCount=7, encoding="utf8")
+ file_handler.setFormatter(log_format)
+ root_log.addHandler(file_handler)
if "COLOREDLOGS_LEVEL_STYLES" not in os.environ:
coloredlogs.DEFAULT_LEVEL_STYLES = {
diff --git a/config-default.yml b/config-default.yml
index ed3c3a638..7400cf200 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -1,4 +1,5 @@
-debug: !ENV ["BOT_DEBUG", "true"]
+debug: !ENV ["BOT_DEBUG", "true"]
+file_logs: !ENV ["FILE_LOGS", "false"]
bot:
diff --git a/docker-compose.yml b/docker-compose.yml
index b3ca6baa4..869d9acb6 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -90,7 +90,6 @@ services:
context: .
dockerfile: Dockerfile
volumes:
- - ./logs:/bot/logs
- .:/bot:ro
tty: true
depends_on: