diff options
| -rw-r--r-- | bot/constants.py | 1 | ||||
| -rw-r--r-- | bot/log.py | 15 | ||||
| -rw-r--r-- | config-default.yml | 3 | ||||
| -rw-r--r-- | docker-compose.yml | 1 | 
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: | 
