【发布时间】: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