我正在使用uwsgi和nginx运行python flask app。我无法让应用程序模块记录。如果我自己运行烧瓶应用程序,我可以看到日志格式正确,但在uwsgi中,我看到没有找到记录器的处理程序......'而且日志丢失了。印刷品很好看。有人可以帮我解决我的错误吗?
由于
我将uwsgi作为
运行 /usr/local/bin/uwsgi --ini /root/uwsgi.ini
# cat /root/uwsgi.ini
[uwsgi]
base=/root/mainapp
app = mainapp
module = %(app)
pythonpath = %(base)
socket = /tmp/mainapp.sock
chmod-socket = 666
callable = app
logto = /var/log/mainapp/app.log
paste-logger = %p
[formatters]
keys: detailed
[handlers]
keys: console
[loggers]
keys: root, module1, module2, module3
[formatter_detailed]
format: %(asctime)s %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s
[handler_console]
class: StreamHandler
args: []
formatter: detailed
[logger_root]
level: DEBUG
handlers:
[logger_module1]
level: DEBUG
qualname: module1
handlers: console
[logger_module2]
level: DEBUG
qualname: module2
handlers: console
[logger_module3]
level: DEBUG
qualname: module3
handlers: console
在模块中,我打电话给
import logging
log = logging.getLogger('module1')
log.info('hello world')
答案 0 :(得分:0)
您是否已将Flask配置为使用记录器?我最喜欢这样的东西应该可以工作
app.config['LOG_FILE'] = 'application.log'
# Configure logger.
if not app.debug:
import logging
from logging import FileHandler
file_handler = FileHandler(app.config['LOG_FILE'])
file_handler.setLevel(logging.WARNING)
app.logger.addHandler(file_handler)
答案 1 :(得分:0)
看起来我必须在我可以做任何事情之前实例化flask的app.logger ...这就是诀窍......在app.logger上设置addhandler并且
import logging
import logging.config
shandler = logging.StreamHandler()
shandler.setLevel(logging.DEBUG)
app.logger.addHandler(shandler)
logging.config.fileConfig('logging.conf')