feat: Add config option redirect_stderr.

Proposed in #282.
This commit is contained in:
Terry Geng 2021-05-26 11:29:22 +08:00
parent efab8928f5
commit 6faadd6669
No known key found for this signature in database
GPG Key ID: F982F8EA1DF720E7
2 changed files with 6 additions and 2 deletions

View File

@ -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

View File

@ -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()