python wsgi信息log进入apache2 error.log

发布于 2025-02-13 18:34:18 字数 1899 浏览 0 评论 0原文

我有一个在Apache上运行的WSGI应用程序。但是我有一个小问题很烦人。我所有的日志都进入了error.log apache2文件,即使是信息日志。

这是我的日志类,如果您有和想法,请提前

class Log:
    def __init__(self, path, smtp):
        self.smtp = smtp
        self.filename = ''
        self.LOGGER = logging.getLogger('Open-Capture')
        if self.LOGGER.hasHandlers():
            self.LOGGER.handlers.clear()  # Clear the handlers to avoid double logs
        log_file = RotatingFileHandler(path, mode='a', maxBytes=5 * 1024 * 1024,
                                       backupCount=2, encoding=None, delay=False)
        formatter = logging.Formatter(
            '[%(name)-17s] [%(file)-26sline %(line_n)-3s] %(asctime)s %(levelname)s %(message)s',
            datefmt='%d-%m-%Y %H:%M:%S')
        log_file.setFormatter(formatter)
        self.LOGGER.addHandler(log_file)

        self.LOGGER.filters.clear()
        self._filter = CallerFilter()
        self.LOGGER.addFilter(self._filter)
        self.LOGGER.setLevel(logging.DEBUG)

    @caller_reader
    def info(self, msg):
        self.LOGGER.info(unidecode(msg))

,这是我的Apache2配置

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/html/opencapture_runtime/
    WSGIDaemonProcess opencapture_runtime user=nathan group=nathan threads=5
    WSGIScriptAlias /runtime /var/www/html/opencapture_runtime/opencapture.wsgi

    <Directory /var/www/html/opencapture_runtime/>
        AllowOverride All
        WSGIProcessGroup opencapture_runtime
        WSGIApplicationGroup %{GLOBAL}
        WSGIPassAuthorization On
        Order deny,allow
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

示例Apache Log:

[Wed Jul 06 10:25:23.577457 2022] [wsgi:error] [pid 37073] [remote ::1:42356] INFO:Open-Capture:Authentification successful. IP Address : ::1

I have a WSGI app running on Apache. But I have a little issue pretty annoying. All my logs goes into the error.log apache2 file, even if it's INFO log.

Here is my Log class, if you have and idea, thanks in advance

class Log:
    def __init__(self, path, smtp):
        self.smtp = smtp
        self.filename = ''
        self.LOGGER = logging.getLogger('Open-Capture')
        if self.LOGGER.hasHandlers():
            self.LOGGER.handlers.clear()  # Clear the handlers to avoid double logs
        log_file = RotatingFileHandler(path, mode='a', maxBytes=5 * 1024 * 1024,
                                       backupCount=2, encoding=None, delay=False)
        formatter = logging.Formatter(
            '[%(name)-17s] [%(file)-26sline %(line_n)-3s] %(asctime)s %(levelname)s %(message)s',
            datefmt='%d-%m-%Y %H:%M:%S')
        log_file.setFormatter(formatter)
        self.LOGGER.addHandler(log_file)

        self.LOGGER.filters.clear()
        self._filter = CallerFilter()
        self.LOGGER.addFilter(self._filter)
        self.LOGGER.setLevel(logging.DEBUG)

    @caller_reader
    def info(self, msg):
        self.LOGGER.info(unidecode(msg))

And here is my apache2 config

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/html/opencapture_runtime/
    WSGIDaemonProcess opencapture_runtime user=nathan group=nathan threads=5
    WSGIScriptAlias /runtime /var/www/html/opencapture_runtime/opencapture.wsgi

    <Directory /var/www/html/opencapture_runtime/>
        AllowOverride All
        WSGIProcessGroup opencapture_runtime
        WSGIApplicationGroup %{GLOBAL}
        WSGIPassAuthorization On
        Order deny,allow
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

Example of apache log :

[Wed Jul 06 10:25:23.577457 2022] [wsgi:error] [pid 37073] [remote ::1:42356] INFO:Open-Capture:Authentification successful. IP Address : ::1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文