这是我的代码: 这在flask和python 3.0中只是一个概念上的证明
from flask import Flask
from flask import request
from flask import jsonify
from flask_cors import CORS
import linecache
import json
import time
import logging
from logging.handlers import RotatingFileHandler
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')
file_handler = RotatingFileHandler('../productpicapi.log', 'a', 1000000, 1)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
logger.addHandler(stream_handler)
def PrintException():
exc_type, exc_obj, tb = sys.exc_info()
f = tb.tb_frame
lineno = tb.tb_lineno
filename = f.f_code.co_filename
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f.f_globals)
return 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(
filename, lineno, line.strip(), exc_obj
)
app = Flask(__name__)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
app.logger = logger
@app.route("/productPicApi/v1/productPicture", methods=["POST"])
def savePicture():
logger.info("inside productpic api")
try:
try :
document = request.form
document = json.loads(document["json"])
logger.info("inside android")
return jsonify({"STATUS": "OK"})
except:
logger.info("inside ios")
document = request.get_json()
r = requests.post(productPictureEndpointUrl, json=document)
array = r.json()
logger.info("return productpic micro")
logger.info(array)
return jsonify(array)
return jsonify({"STATUS": "KO"})
except Exception as e:
print("error")
print(e)
return jsonify(
{
"STATUS": "KO",
"EXCEPTION": PrintException() + " " + str(e),
"DOCUMENT": document,
"ORIGIN": "ProductPicApi",
}
)
if __name__ == "__main__":
logger.info("productPictureEndpointUrl")
app.run(host="0.0.0.0", port=portPicApi,debug=True)
但是日志文件为空,是的,我已经检查了上面的目录。 为什么不将其写入日志文件? 通常,它至少应该写入文件中的某些内容... 通常记录器应该执行此操作吗? 有没有办法在烧瓶中使用旋转式原木? 长颈瓶能抓住我的记录仪吗?