diff --git a/configuration.example.ini b/configuration.example.ini index 4f683de..9a9aeff 100644 --- a/configuration.example.ini +++ b/configuration.example.ini @@ -84,7 +84,10 @@ port = 64738 #pip3_path = venv/bin/pip # 'logfile': write logs into this file. +# 'redirect_strerr': capture outputs from stderr and write into the `logfile`, +# useful for capture the exception message when the bot crash. #logfile = +#redirect_strerr = False #announce_current_music = True #allow_other_channel_message = False diff --git a/mumbleBot.py b/mumbleBot.py index 58d997e..11bc480 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -802,8 +802,9 @@ if __name__ == '__main__': if logfile: print(f"Redirecting stdout and stderr to log file: {logfile}") handler = logging.handlers.RotatingFileHandler(logfile, mode='a', maxBytes=10240) # Rotate after 10KB - sys.stdout = util.LoggerIOWrapper(bot_logger, logging.INFO, fallback_io_buffer=sys.stdout.buffer) - sys.stderr = util.LoggerIOWrapper(bot_logger, logging.INFO, fallback_io_buffer=sys.stderr.buffer) + if var.config.getboolean("bot", "redirect_stderr", fallback=False): + sys.stderr = util.LoggerIOWrapper(bot_logger, logging.INFO, + fallback_io_buffer=sys.stderr.buffer) else: handler = logging.StreamHandler()