from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
app.logger.debug('This is a debug message.')
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True)
import multiprocessing
import logging.config
bind = "0.0.0.0:5000"
workers = 1
accesslog = "./logs/access.log"
errorlog = "./logs/error.log"
loglevel = "debug"
capture_out = True
daemon = True
reload = True
log_config = {
'version': 1,
'formatters': {
'detailed': {
'class': 'logging.Formatter',
'format': '%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] [%(funcName)s()] %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
},
'handlers': {
'file_handler': {
'class': 'logging.FileHandler',
'filename': errorlog,
'formatter': 'detailed',
'level': 'DEBUG',
},
},
'loggers': {
'flask_test': {
'handlers': ['file_handler'],
'level': 'DEBUG',
'propagate': True,
},
},
}
logging.config.dictConfig(log_config)
gunicorn -c config_test.py flask_test:app
fuser -v -n tcp 5000
fuser -k 5000/tcp
- 浏览器输入
http://10.168.20.236:5000/
- 输出
Hello, World!