Server Access Log

Since v0.7 To manage aah server effectively it is necessary to know details about the request, response, processing time, client IP address, etc. aah provides the flexible and configurable server access log capabilities.

Access log processing handled in separate goroutine, it won’t stand in way.

Table of Contents

Supported Access Log flag

Log FlagDescription
clientipClient IP address aka Remote IP address
reqtimeTime of the request is received by server. Local time in default format RFC3339 or you can provide your format
requrlRelative request URL not including query string
reqmethodRequest HTTP method
reqprotoRequest Protocol. For e.g: HTTP/1.1, HTTP/2.0
reqidRequest ID if present otherwise value - is logged. Refer to config request.id.header in the aah.conf
reqhdr:<header_name>Request header, if present otherwise value - is logged
querystrRequest query string if present otherwise value - is logged
resstatusResponse Status Code
ressizeBytes sent, excluding response HTTP headers, otherwise value - is logged; if no bytes were sent
reshdr:<header_name>Response header, if present otherwise value - is logged
restimeRequest processing time in milliseconds. The time elapsed between the request received by server and the last bytes were written on the wire by server
customAdd non-space string into log string

Default access log pattern

%clientip %custom:- %reqtime %reqmethod %requrl %reqproto %resstatus %ressize %restime %reqhdr:referer

Sample Server Access Log of default pattern

::1 - 2017-07-21T14:56:15-07:00 GET / HTTP/2.0 200 12735 0.7020 "https://aahframework.org/"
::1 - 2017-07-21T14:56:15-07:00 GET /assets/css/aah-f2f8e6e.css HTTP/2.0 200 7408 0.3377 "https://aahframework.org/"
::1 - 2017-07-21T14:56:15-07:00 GET /assets/js/aah-f2f8e6e.js HTTP/2.0 200 522 0.2688 "https://aahframework.org/"
::1 - 2017-07-21T14:56:15-07:00 GET /assets/css/bootstrap.min.css HTTP/2.0 200 125523 4.1035 "https://aahframework.org/"
::1 - 2017-07-21T14:56:15-07:00 GET /assets/img/aah-logo-64x64.png HTTP/2.0 200 2404 0.2033 "https://aahframework.org/"
::1 - 2017-07-21T14:56:15-07:00 GET /assets/js/ie10-viewport-bug-workaround.js HTTP/2.0 200 651 0.2062 "https://aahframework.org/"
::1 - 2017-07-21T14:56:15-07:00 GET /assets/fonts/timeburnerbold.ttf HTTP/2.0 200 78170 1.4987 "https://aahframework.org/assets/css/aah-f2f8e6e.css"

Access Log Configuration

access_log { ... } configuration goes under config section server { ... } in the aah.conf..

# -----------------------------------------------------------------------------
# Access Log configuration
# To manage aah server effectively it is necessary to know details about the
# request, response, processing time, client IP address, etc. aah provides
# the configurable access log capabilities.
#
# Doc: https://docs.aahframework.org/server-access-log.html
# -----------------------------------------------------------------------------
access_log {
  # Enabling server access log
  # Default value is `false`
  enable = true

  # Absolute path to access log file or relative path.
  # Default location is application logs directory
  #file = "{{ .AppName }}-access.log"

  # Default server access log pattern
  #pattern = "%clientip %custom:- %reqtime %reqmethod %requrl %reqproto %resstatus %ressize %restime %reqhdr:referer"

  # Access Log channel buffer size
  # Default value is `500`
  #channel_buffer_size = 500

  # Include static files access log too.
  # Default value is `true`.
  #static_file = false
}

Examples

Added respective flag into pattern config.

Logging User-Agent

// header name in-casesensitive
reqhdr:User-Agent

# OR
reqhdr:user-agent

Logging Referer URL

// header name in-casesensitive
reqhdr:referer