0

In httpd's access logs, I want to get a log as soon as an API is hit. With the current access log configuration in httpd.conf(below), the API logs come in only when the response comes

<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>

Sample output that I get in 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 )"

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 ( compatible )"

The problem is that sometimes my APIs remain in processing mode, ex: a long running query gets hit, and the system slows down. Since I dont get any log of the API which is hit until it is returned, debugging becomes a nightmare.

Is there an access_log configuration in httpd.conf which would help insert a log in access_log file as soon as the API is hit?

Community
  • 1
  • 1
Ouroboros
  • 1,432
  • 1
  • 19
  • 41

1 Answers1

0

Not with these directives and the standard logging module, that is how Apache logging is built.

However log_forensic (https://httpd.apache.org/docs/2.4/mod/mod_log_forensic.html ) is built exactly for that. You have less control, but you do see logs before the request is processed.

From the link:

This module provides for forensic logging of client requests. Logging is done before and after processing a request, so the forensic log contains two log lines for each request.

(my emphasis)

Nic3500
  • 8,144
  • 10
  • 29
  • 40