【问题标题】:Entry in httpd's access_log as soon as the API is hit命中 API 后立即进入 httpd 的 access_log
【发布时间】:2019-04-07 08:23:54
【问题描述】:

在 httpd 的访问日志中,我想在命中 API 时立即获取日志。使用 httpd.conf 中的当前访问日志配置(如下),API 日志仅在响应到来时才会出现

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b %{ms}T \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b %{ms}T" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b %{ms}T \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    #CustomLog "logs/access_log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    CustomLog "logs/access_log" combined
</IfModule>

我在 access_logs 中获得的示例输出

1.187.15.66 - - [03/Nov/2018:08:16:10 +0000] "POST /v13/user/login HTTP/1.1" 200 1394

1.187.15.66 - - [03/Nov/2018:08:16:10 +0000] "POST /v13/user/login HTTP/1.1" 200 1394 1556 "-" "Mozilla/5.0 (兼容)"

49.14.67.179 - - [03/Nov/2018:08:16:11 +0000] "POST /v13/zvice/detailscard/9J5EDAR3Y2PZA HTTP/1.1" 200 37133

49.14.67.179 - - [03/Nov/2018:08:16:11 +0000] "POST /v13/zvice/detailscard/9J5EDAR3Y2PZA HTTP/1.1" 200 37133 4254 "-" “Mozilla/5.0(兼容)”

问题是有时我的 API 仍处于处理模式,例如:长时间运行的查询被命中,系统变慢。由于在返回之前我没有得到任何命中的 API 日志,因此调试成为一场噩梦。

httpd.conf 中是否有 access_log 配置,这有助于在 API 被命中后立即在 access_log 文件中插入日志?

【问题讨论】:

    标签: apache httpd.conf access-log


    【解决方案1】:

    不使用这些指令和标准日志记录模块,Apache 日志记录就是这样构建的。

    然而 log_forensic (https://httpd.apache.org/docs/2.4/mod/mod_log_forensic.html) 正是为此而构建的。您的控制权较少,但您确实会在处理请求之前看到日志。

    来自链接:

    此模块提供客户端请求的取证记录。 日志记录 在处理请求之前和之后完成,所以取证日志 每个请求包含两个日志行。

    (我的重点)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-02
      • 2014-03-30
      • 1970-01-01
      • 2014-06-07
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      相关资源
      最近更新 更多