Closed DominicFrei closed 2 years ago
Maybe this would be best as a config variable. I like seeing the live output of the bot, and it helps me see if I ran into the rare issue of a failed network request crashing one of the threads. Maybe something like CONSOLE_LOGGING: True
as a default in the config under the logging section.
I had a minute to do it. I tested this and it works as intended. Just commit this to your branch and it should be good to go.
Here's the update to logger.py
:
# Get logging variables
log_level = config['LOGGING']['LOG_LEVEL']
log_file = config['LOGGING']['LOG_FILE']
log_to_console = config['LOGGING']['CONSOLE_LOGGING']
file_handler = TimedRotatingFileHandler(log_path, when="midnight")
if log_to_console:
log.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
handlers=[file_handler, logging.StreamHandler()])
else:
log.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
handlers=[file_handler])
logger = logging.getLogger(__name__)
level = logging.getLevelName(log_level)
logger.setLevel(level)
Also update config.example.yml
:
LOGGING:
CONSOLE_LOGGING: True
LOG_LEVEL: INFO
LOG_FILE: bot.log
@Jrjy3 Yup, it does. Implemented it at the same time too. ;) I might have one more addition to this though. So in case this gets approved please wait a moment with the merge. I don't like the duplicated code in my solution.
Alright, done. Ready for review again.
This PR removed the console log. We do log to a file already anyway, removing the console saves us valuable time.