【问题标题】:How to manage mod_wsgi logs in apache?如何在 apache 中管理 mod_wsgi 日志?
【发布时间】:2016-10-09 22:40:04
【问题描述】:

我正在开发烧瓶应用程序,我使用 mod_wsgi 和 Apache 来托管烧瓶应用程序。我已经在应用程序中设置了日志记录,但我观察到在 apache/logs/error.log 中写入了相同的日志 喜欢

[wsgi:error] ... BACK TO THE BROWSER
[wsgi:error] ... Selected records from table 
[wsgi:error] ... mod_wsgi (pid=1654): Exception occurred processing WSGI script '/tmp/mod_wsgi-localhost:8000:0/htdocs/'.
[wsgi:error] ... ID 1123 Inserted in table

由于这个 error.log 被 wsgi:error 和 apache 错误污染,因此很难分析日志文件。

他们有什么方法可以停止在 error.log 文件中写入 wsgi.errors,还是我们可以将这些特定日志重定向到单独的日志文件?

【问题讨论】:

  • 你的 apache/log/error.log 在哪里?

标签: python flask mod-wsgi apache2.4


【解决方案1】:

我通常会在我的 VirtualHost 中添加一个 ErrorLog。这是我使用的 Apache VirtualHost 示例:

<VirtualHost *:443>

  ServerName yourservername.com
  ErrorLog /home/yourusername/apache_errors.log

  WSGIDaemonProcess yourproject-https python-home=/home/yourusername/.virtualenvs/yourproject
  WSGIScriptAlias /yourproject /var/www/html/yourproject/yourproject/wsgi.py process-group=yourproject-https application-group=yourproject-https
  WSGIProcessGroup yourproject-https
  Alias /yourproject/static/ /var/www/html/yourproject/static/

  SSLENGINE on 

  SSLCertificateFile /etc/pki/tls/certs/localhost.crt
  SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
  SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
  SSLProtocol all -SSLv2
</VirtualHost>

这样可以吗?当然,您可以选择主目录以外的路径。

【讨论】:

  • 我有相同的设置,但仍然 wsgi 错误被记录在 error.log 和 apache_errors.log 中(这里只有例外):S
  • @Shashi 我也做了同样的观察。
  • 这将只记录ServerNameServerAlias 中指定的域的错误,在此示例中,仅记录https 的错误。
【解决方案2】:

首先,您应该在 VirtualHost 中添加 ErrorLog,然后您应该使用flask.logging.default_handler 来记录您的消息。

请注意,如果您的请求应用程序不存在于您的 threadLocal 环境中,flask 将使用 std.strerr 来记录消息,这是由于消息被主日志而不是 VirtualHost 日志缓存。

【讨论】:

    猜你喜欢
    • 2011-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多