mod_wsgi-express设置日志级别

时间:2016-04-12 08:15:40

标签: python mod-wsgi

如何在以

开头的wsgi应用程序中设置日志级别
mod_wsgi-express ./mywsgi.py

?这是最简单的设置。 Logging in python + mod_wsgi app讨论配置文件,Quick Configuration Guide也是如此。 mod_wsgi-express命令只需要运行python wsgi文件。

使用the release notes

中提到的--log-level标记
mod_wsgi-express --log-level info ./mywsgi.py

未显示logging.info条消息。 --debug-mode旗帜mentioned by @GrahamDumpleton也没有。

解决了(见下文),但仍然是:最小的例子

import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)

def application(environ, start_response):
    status = '200 OK'
    logging.warning('warning log message')
    logging.info('info log message')

    output = "hello world"

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

1 个答案:

答案 0 :(得分:0)

您也(请参阅上面的示例)需要在wsgi程序中启用INFO(f.ex。)级别日志记录。例如通过线

logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)

如果您从--log-level info开始,则会在logging.info中看到error_log输出。

相关问题