diff options
| author | 2021-11-12 06:09:32 +0400 | |
|---|---|---|
| committer | 2021-11-12 06:09:32 +0400 | |
| commit | 6a9f1886c70658636f36272ea8b8f4c3f5f4a7a9 (patch) | |
| tree | e3c76d81ac98e4b1c247fc30c65780cd874e45e4 /bot/log.py | |
| parent | Merge pull request #858 from Numerlor/coloredlogs (diff) | |
Disable File Logs In Production
The most recent changes to our log setup had the loggers writing to a
read-only location in prod. This would cause an error during startup.
To get around this while keeping the change, I moved it to only be used
if debug is True.
Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'bot/log.py')
| -rw-r--r-- | bot/log.py | 23 | 
1 files changed, 13 insertions, 10 deletions
| @@ -18,19 +18,22 @@ def setup() -> None:      format_string = "%(asctime)s | %(name)s | %(levelname)s | %(message)s"      log_format = logging.Formatter(format_string) +    root_logger = logging.getLogger() -    # Set up file logging -    log_file = Path("logs/sir-lancebot.log") -    log_file.parent.mkdir(exist_ok=True) +    # Copied from constants file, which we can't import yet since loggers aren't instantiated +    debug = os.environ.get("BOT_DEBUG", "true").lower() == "true" -    # File handler rotates logs every 5 MB -    file_handler = logging.handlers.RotatingFileHandler( -        log_file, maxBytes=5 * (2 ** 20), backupCount=10, encoding="utf-8", -    ) -    file_handler.setFormatter(log_format) +    if debug: +        # Set up file logging +        log_file = Path("logs/sir-lancebot.log") +        log_file.parent.mkdir(exist_ok=True) -    root_logger = logging.getLogger() -    root_logger.addHandler(file_handler) +        # File handler rotates logs every 5 MB +        file_handler = logging.handlers.RotatingFileHandler( +            log_file, maxBytes=5 * (2 ** 20), backupCount=10, encoding="utf-8", +        ) +        file_handler.setFormatter(log_format) +        root_logger.addHandler(file_handler)      if "COLOREDLOGS_LEVEL_STYLES" not in os.environ:          coloredlogs.DEFAULT_LEVEL_STYLES = { | 
