-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.6
kwmccabe edited this page Apr 17, 2018
·
12 revisions
v0.6 - app.init_logging(), LOG_FILE, LOG_LEVEL, logging.info()
- +8 -0 [M] web/app/init.py
- +8 -0 [M] web/config.py
- +3 -0 [M] web/flaskapp.py
- Create method
init_logging()
. - Set basic logging options using
LOG_FILE
andLOG_LEVEL
fromapp.config
. - Call
logging.debug()
to test.
app.config.from_object(config[config_name])
config[config_name].init_app(app)
+ init_logging(app)
return app
+def init_logging(app):
+ import logging
+ logging.basicConfig( filename = app.config['LOG_FILE'], level = app.config['LOG_LEVEL'] )
+ logging.debug("init_logging( filename = %s, level = %i )" % (app.config['LOG_FILE'],app.config['LOG_LEVEL']))
- Set
LOG_FILE
andLOG_LEVEL
in commonAppConfig
. - Override
LOG_LEVEL
per deployment stage.
+import logging
+_basedir = os.path.abspath(os.path.dirname(__file__))
class AppConfig(object):
SECRET_KEY = os.environ.get('SECRET_KEY') or 'kp-cUHRAYH1n-sPaJICcEE2kOpU62mCk'
+ LOG_FILE = _basedir+'/logs/flaskapp.log'
+ LOG_LEVEL = logging.ERROR # CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET
...
class DevelopmentConfig(AppConfig):
DEBUG = True
+ LOG_LEVEL = logging.DEBUG
class TestingConfig(AppConfig):
TESTING = True
+ LOG_LEVEL = logging.INFO
class ProductionConfig(AppConfig):
DEBUG = False
TESTING = False
+ LOG_LEVEL = logging.WARNING
@classmethod
def init_app(cls, app):
- Add some
logging.info()
statements
+import logging
...
@app.route('/')
def hello_flaskapp():
+ logging.info("hello_flaskapp()")
return 'Hello FlaskApp'
...
@app.route('/debug')
def hello_debug():
import pdb; pdb.set_trace()
+ logging.info("hello_debug()")
return "Hello Python Debugger"
Commit-v0.5 | Commit-v0.6 | Commit-v0.7
- FlaskApp Tutorial
- Table of Contents
- About
- Application Setup
- Modules, Templates, and Layouts
- Database Items, Forms, and CRUD
- List Filter, Sort, and Paginate
- Users and Login
- Database Relationships
- API Module, HTTPAuth and JSON
- Refactoring User Roles and Item Status
- AJAX and Public Pages