-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.6
kwmccabe edited this page Apr 10, 2018
·
12 revisions
app.init_logging(), LOG_FILE, LOG_LEVEL, logging.info()
-
+4 -0 [M] docker-compose.yml
-
+1 -1 [M] web/Dockerfile
-
+8 -0 [M] web/app/init.py
-
+8 -0 [M] web/config.py
-
+3 -0 [M] web/flaskapp.py
-# copy code from current directory into working directory
+# copy project files into working directory
Create method init_logging(). Set basic logging options using LOG_FILE and LOG_LEVEL from config. Call logging.debug() to test.
from flask import Flask
from config import config
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 and LOG_LEVEL in common AppConfig 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
@staticmethod
def init_app(app):
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"
- 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