flask-boilerplate
flask-boilerplate copied to clipboard
Logger Setup Issue
Within the logger_setup.py
file there is a mistake in this code here.
if app.config.get('LOG_FILE'): file_handler = RotatingFileHandler(app.config['LOG_FILENAME'], app.config['LOG_MAXBYTES'], app.config['LOG_BACKUPS'], 'a', encoding='utf-8') file_handler.setLevel(logging.DEBUG) app.logger.addHandler(file_handler)
The first possible mistake or maybe just something that most people might glance over is the fact that unless you setup within your config.py
or any of the config files, a variable called LOG_FILE
and set it to some value that does not come out to None or False then it will never enter the if statement. Maybe this was meant to say if app.config.get('LOG_FILENAME'):
because that variable exists so this will run.
Although, one the loop is entered for the above code a TypeError exception is raised because the arguments passed to RotatingFileHandler are passed in the wrong order and what should be the backupCount argument (an integer) is actually passed the mode argument (a string) which you later run into comparing a string to an int which won't work. A simple fix would be to change the above to what I am posting below, or just change the order, though it may be more helpful to future users to explicitly pass them like below
if app.config.get('LOG_FILENAME'): file_handler = RotatingFileHandler(filename=app.config['LOG_FILENAME'], maxBytes=app.config['LOG_MAXBYTES'], backupCount=app.config['LOG_BACKUPS'], mode='a', encoding='utf-8') file_handler.setLevel(logging.DEBUG) app.logger.addHandler(file_handler)