Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

Logger Setup Issue #5

Open
Kbman99 opened this issue Apr 10, 2017 · 0 comments
Open

Logger Setup Issue #5

Kbman99 opened this issue Apr 10, 2017 · 0 comments

Comments

@Kbman99
Copy link
Contributor

Kbman99 commented Apr 10, 2017

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant