[英]log is not writing into file
I want to write log into file. 我想将日志写入文件。 File is creating but nothing is writing into file.
文件正在创建,但是什么也没有写入文件。 my code is:
我的代码是:
app = Flask(__name__)
formatter = logging.Formatter("[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
handler = RotatingFileHandler('/var/log/httpd/myfile.log', maxBytes=100000, backupCount=10)
handler.setLevel(logging.INFO)
handler.setFormatter(formatter)
logger = logging.getLogger("__init__")
logger.setLevel(logging.INFO)
logger.addHandler(handler)
@app.route('/api/urlname', methods=['GET'])
def api_url():
logger.info("----- REST API is called -----")
....
.....
if __name__ == '__main__':
app.run()
When calling /api/urlname code is executing and getting result but not see any log in file. 调用/ api / urlname代码时,正在执行代码并获得结果,但看不到任何登录文件。 I gave full permission to myfile.log like: sudo chmod -R 777 myfile.log.
我对myfile.log授予了完全许可,例如:sudo chmod -R 777 myfile.log。
Can you tell where I did wrong and why log is not writing into file? 您能告诉我我做错了什么以及为什么日志未写入文件吗?
您应该将setLevel(logging.info)
都更改为setLevel(logging.INFO)
因为logging.info
是一个函数,而logging.INFO
是一个整数(在本例中为20),代表信息日志记录的日志记录级别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.