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. I gave full permission to myfile.log like: 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),代表信息日志记录的日志记录级别。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.