首页 > 解决方案 > 如果 python 烧瓶应用程序在 apache2 mod_wsgi 下运行,则无法写入日志文件

问题描述

当我运行 app.py 使用命令行没有问题时,将生成并记录日志文件。

但是当 py 文件由 apache wsgi 运行时

没有日志出来

file_log_path = '/var/log/apache2/'
file_log = 'python_app_log.txt'
file_log_full = file_log_path + file_log

logging.basicConfig(filename = file_log_full, level=logging.INFO,
                    format="%(asctime)s|%(levelname)s|%(funcName)s| %(message)s")

logging.info('Finished init path')

#----- Main-Fucntions ------------------------------------
#-- Set up time ---
logging.info('Main-Fucntions Init...')
tz_utc = tz.tzoffset('UTC Time', 0 * 60)
tz_sql = tz.tzoffset('SQL Server Time', Get_MySQL_TimeZone() * 60)

logging.info(tz_utc)
logging.info('MySQL Server Time zone is ' + tz_sql._name)



#----- Main Process Code must in above--------------------------------------
if __name__ == "__main__":
    app.run(host='0.0.0.0')
    #app.run(host='0.0.0.0',debug=True)
    #app.run(host= '0.0.0.0', port = 30443 ,debug = True)
    logging.info('APP RUN Event')

标签: pythonflaskloggingapache2mod-wsgi

解决方案


推荐阅读