Created
October 12, 2012 18:26
-
-
Save tzulberti/3880691 to your computer and use it in GitHub Desktop.
Flask logging example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app.py file | |
| import logging_conf | |
| app = Flask(__name__) | |
| # -------------------------------------------- | |
| # logging_conf.py | |
| import logging | |
| from os.path import join | |
| from logging.handlers import TimedRotatingFileHandler | |
| class CURRENT_ENVIRONMENT(object): | |
| LOGGING_FOLDER = '.' | |
| root_logger = logging.getLogger() | |
| root_handler = TimedRotatingFileHandler( | |
| filename=join(CURRENT_ENVIRONMENT.LOGGING_FOLDER, 'web.log'), | |
| when='midnight', | |
| backupCount=10 | |
| ) | |
| root_handler.setLevel(logging.DEBUG) | |
| root_logger.addHandler(root_handler) | |
| sqlalchemy_logger = logging.getLogger('sqlalchemy') | |
| sql_time_rotating_handler = TimedRotatingFileHandler( | |
| filename=join(CURRENT_ENVIRONMENT.LOGGING_FOLDER, 'sqlalchemy.log'), | |
| when='midnight', | |
| backupCount=10 | |
| ) | |
| sql_time_rotating_handler.setLevel(logging.DEBUG) | |
| sqlalchemy_logger.addHandler(sql_time_rotating_handler) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment