Last active
June 25, 2019 17:09
-
-
Save NoFishLikeIan/4b1b918a4fc684d932ff9c772721712d to your computer and use it in GitHub Desktop.
bootstrap-flask
This file contains 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
from loguru import logger | |
from src.server import app, app_config | |
if __name__ == '__main__': | |
port = app_config['port'] | |
host = app_config['host'] | |
logger.info(f'Running on {host}:{port}') | |
app.run(**app_config) |
This file contains 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
import os | |
from flask import Flask | |
from dotenv import load_dotenv | |
from loguru import logger | |
from .setup import set_logger_path | |
# logger | |
logger_path = set_logger_path() | |
logger.add(os.path.join(logger_path, 'server.log'), format="{time:YYYY-MM-DD at HH:mm:ss} {level} - {message}", level='INFO', retention='1 day') | |
logger.add(os.path.join(logger_path, 'error.log'), format='{time:YYYY-MM-DD at HH:mm:ss} {level} - {message}', level='ERROR', retention='10 days') | |
# .env variables | |
load_dotenv() | |
PORT = os.getenv('PORT', 5000) | |
DEBUG = os.getenv('DEBUG', False) | |
HOST = os.getenv('HOST', '0.0.0.0') | |
THREADED = os.getenv('THREADED', False) | |
app_config = { | |
'port': PORT, | |
'debug': DEBUG, | |
'host': HOST, | |
'threaded': THREADED | |
} | |
# app | |
app = Flask(__name__) |
This file contains 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
import os | |
def set_logger_path(): | |
log_path = os.getenv('LOG_PATH') | |
if log_path is None: | |
if not os.path.isdir('logs/'): | |
os.makedirs('logs/') | |
log_path = 'logs/' | |
return log_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment