按下API后立即在httpd的access_log中输入

时间:2018-11-03 08:20:40

标签: apache httpd.conf access-log

在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(compatible)” < / p>      

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文件中插入日志?

1 个答案:

答案 0 :(得分:0)

没有这些指令和标准的日志记录模块,这就是Apache日志记录的构建方式。

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

通过链接:

  

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

(我的重点)