Formatting Log Files

This section covers the creation of logging formats. All but a few logging output related settings in Traffic Server are performed in logging.yaml and consulting the documentation for that file is recommended in addition to this section. Any configurations or settings performed outside that file will be clearly noted.

Defining Formats

Logging formats in Traffic Server are defined by editing logging.yaml and adding new format entries for each format you wish to define. The syntax is fairly simple: every format must contain a Format attribute, which is the string defining the contents of each line in the log, and may also contain an optional Interval attribute defining the log aggregation interval for any logs which use the format (see Summary Logs for more information).

The return value from the format function is the log format object which may then be supplied to the appropriate log.* functions that define your logging destinations.

A very simple example, which contains only the timestamp of when the event began and the canonical URL of the request, would look like:

  1. formats:
  2. - name: myformat
  3. format: '%<cqtq> %<cauc>'

You may include as many custom field codes as you wish. The full list of codes available can be found in Log Fields. You may also include any literal characters in your format. For example, if we wished to separate the timestamp and canonical URL in our customer format above with a slash instead of a space, or even a slash surrounded by spaces, we could do so by just adding the desired characters to the format string:

  1. formats:
  2. - name: myformat
  3. format: '%<cqtq> / %<cauc>'

You may define as many custom formats as you wish. To apply changes to custom formats, you will need to run the command traffic_ctl config reload after saving your changes to logging.yaml.

Log Fields

The following sections detail all the available Traffic Server logging fields, broken down into the following broad categories for (hopefully) easier reference:

Individual log fields are used within a log format string by enclosing them in angle brackets and prefixing with a percent sign. For example, to use the log field cqhl (the length in bytes of the client request headers), you would do the following:

  1. Format = '%<cqhl>'

Literal characters may be used, but they must be outside the log fields’ placeholders, as so:

  1. Format = 'Client Header Length (bytes): %<cqhl>'

You may combine many fields into a single format string (logs wouldn’t be very useful if you couldn’t). Some fields do require a little extra treatment, which is noted clearly in their descriptions below. This affects, primarily, those fields which provide access to HTTP header values as you need to specify which header’s value you wish to appear in the log data. For these, the header name is noted inside the angle brackets, before the log field name, and are enclosed within a curly braces pair. For example, to include the value of the Age header from an origin server response you would do:

  1. Format = '%<{Age}ssh>'

Authentication

These log fields provide access to various details of a client or proxy’s means of request authentication to their destination (whether it be the client request to a proxy server, or the proxy server’s request to an origin).

FieldSourceDescription
caunClient RequestAuthentication User name as a result of the RFC931/ident lookup for the client-provided name.

Cache Details

These log fields reveal details of the Traffic Server proxy interaction with its own cache while attempting to service incoming client requests.

FieldSourceDescription
clucClient RequestCache Lookup URL, also known as the cache key, which is the canonicalized version of the client request URL.
crcProxy CacheCache Result Code. The result of Traffic Server attempting to obtain the object from cache; Logging Cache Results.
crscProxy CacheCache Result Sub-Code. More specific code to complement the Cache Result Code.
chmProxy CacheCache Hit-Miss status. Specifies the level of cache from which this request was served by Traffic Server. Currently supports only RAM (HIT_RAM) vs disk (HIT_DISK).
cwrProxy CacheCache Write Result. Specifies the result of attempting to write to cache: not relevant (-), no cache write (WL_MISS), write interrupted (INTR), error while writing (ERR), or cache write successful (FIN).
cwtProxy CacheCache Write Transform Result.
crraProxy CacheCache read retry attempts to read the object from cache.
cwraProxy CacheCache write retry attempts to write a fresh or updated object to cache.
cccsProxy CacheCache collapsed connection success; -1: collapsing was attempted but failed, request went upstream 0: collapsing was unnecessary 1: attempted to collapse and got a cache hit on subsequent read attempts

Connections and Transactions

The following log fields are used to list various details of connections and transactions between Traffic Server proxies and origin servers.

FieldSourceDescription
scaProxyNumber of attempts within the current transaction by Traffic Server in connecting to the origin server.
sstcProxyNumber of transactions between the Traffic Server proxy and the origin server from a single session. Any value greater than zero indicates connection reuse.
ccidClient RequestClient Connection ID, a non-negative number for a connection, which is different for all currently-active connections to clients.
ctidClient RequestClient Transaction ID, a non-negative number for a transaction, which is different for all currently-active transactions on the same client connection. For client HTTP/2 transactions, this value is the stream ID for the transaction.
ctpwClient RequestClient Transaction Priority Weight, the priority weight for the underlying HTTP/2 protocol.
ctpdClient RequestClient Transaction Priority Dependence, the transaction ID that the current transaction depends on for HTTP/2 priority logic.

Content Types

Log fields used to reveal the HTTP content types in effect for transactions.

FieldSourceDescription
psctOrigin Server ResponseContent type of the document obtained by Traffic Server from the origin server response.

Error Code

The log fields of error code which is triggered session close or transaction close. The first byte of this field indicates that the error code is session level (S) or transaction level (T). When no error code is received or transmitted, these fields are -. For HTTP/2, error code are described in RFC 7540 section 7.

FieldSourceDescription
crecClient RequestError code in hex which Traffic Server received
ctecClient ResponseError code in hex which Traffic Server transmitted

Hierarchical Proxies

The log fields detail aspects of transactions involving hierarchical caches.

FieldSourceDescription
phrProxyProxy Hierarchy Route. Specifies the route through configured hierarchical caches used to retrieve the object.

HTTP Headers

The following log tables provide access to the values of specified HTTP headers from each phase of the transaction lifecycle. Unlike many of the other log fields, these require a little extra notation in the log format string, so that Traffic Server knows the individual HTTP header from which you aim to extract a value for the log entry.

This is done by specifying the name of the HTTP header in curly braces, just prior to the log field’s name, as so:

  1. Format = '%<{User-agent}cqh>'

The above would insert the User Agent string from the client request headers into your log entry (or a blank string if no such header was present, or it did not contain a value).

FieldSourceDescription
cqhClient RequestLogs the value of the named header from the client’s request to the Traffic Server proxy.
pqhProxy RequestLogs the value of the named header from the Traffic Server proxy’s request to the origin server.
pshProxy ResponseLogs the value of the named header from the Traffic Server proxy’s response to the client.
sshOrigin ResponseLogs the value of the named header from the origin server’s response to the proxy.
csshCached Origin ResponseLogs the value of the named header from the cached origin server response.

Each of these also includes a URI-encoded variant, which replaces various characters in the string with entity encodings - rendering them safe for use in URL path components or query parameters. The variants’ names follow the pattern of the origin field named prefixed with e, as shown here:

Original FieldURL-Encoded Variant
cqhecqh
pqhepqh
pshepsh
sshessh
csshecssh

HTTP Methods

These fields are used to log information about the HTTP methods/verbs used by requests.

FieldSourceDescription
cqhmClient RequestHTTP method used in the client request to the Traffic Server proxy (e.g. GET, POST, etc.).

Identifiers

Logging fields used to obtain various unique identifiers for transactions or objects.

FieldSourceDescription
cridClient RequestSequence number of the current client request. Resets to 0 on every Traffic Server restart.
cruuidClient RequestUUID of the current client request; generated by concatenating the puuid and crid field values.
puuidProxy ServerUUID for the currently running traffic_server process. Regenerated on every Traffic Server startup.

Lengths and Sizes

These log fields are used to obtain various lengths and sizes of transaction components (headers, content bodies, etc.) between clients, proxies, and origins. Unless otherwise noted, all lengths are in bytes.

FieldSourceDescription
cqclClient RequestClient request content length, in bytes.
cqhlClient RequestClient request header length, in bytes.
cqqlClient RequestClient request header and content length combined, in bytes.
cssclCached Origin ResponseContent body length from cached origin response.
csshlCached Origin ResponseHeader length from cached origin response.
cssqlCached Origin ResponseContent and header length from cached origin response.
fsizOriginSize of the file as seen by the origin server.
pqclProxy RequestContent body length of the Traffic Server proxy request to the origin server.
pqhlProxy RequestHeader length of the Traffic Server proxy request to the origin server.
pqqlProxy RequestContent body and header length combined, of the Traffic Server request to the origin server.
psclProxy ResponseContent body length of the Traffic Server proxy response.
pshlProxy ResponseHeader length of the Traffic Server response to client.
psqlProxy ResponseContent body and header length combined of the Traffic Server response to client.
ssclOrigin ResponseContent body length of the origin server response to Traffic Server.
sshlOrigin ResponseHeader length of the origin server response.
ssqlOrigin ResponseContent body and header length combined of the origin server response to Traffic Server.

Log Collation

Logging fields related to Log Collation.

FieldSourceDescription
phnProxyHostname of the Traffic Server node which generated the collated log entry.
phiProxyIP of the Traffic Server node which generated the collated log entry.

Note

Log collation is a deprecated feature as of ATS v8.0.0, and will be removed in ATS v9.0.0.

Network Addresses, Ports, and Interfaces

The following log fields are used to log details of the network (IP) addresses, incoming/outgoing ports, and network interfaces used during transactions.

FieldSourceDescription
chiClientIP address of the client’s host.
chihClientIP address of the client’s host, in hexadecimal.
hiiProxyIP address for the proxy’s incoming interface (to which the client connected).
hiihProxyIP address for the proxy’s incoming interface (to which the client connected), in hexadecimal.
chpClientPort number of the client’s host.
phpProxy ResponseTCP port number from which Traffic Server serviced the request.
pqsiProxy RequestIP address from which Traffic Server issued the proxy request to the origin server. Cache hits will result in a value of 0.
pqspProxy RequestPort number from which Traffic Server issued the proxy request to the origin server. Cache hits will yield a value of 0.
shiOrigin ServerIP address resolved via DNS by Traffic Server for the origin server. For hosts with multiple IP addresses, the address used by Traffic Server for the connection will be reported. See note below regarding misleading values from cached documents.
shnOrigin ServerHost name of the origin server.
nhiOrigin ServerDestination IP address of next hop
nhpOrigin ServerDestination port of next hop

Note

This can be misleading for cached documents. For example: if the first request was a cache miss and came from IP1 for server S and the second request for server S resolved to IP2 but came from the cache, then the log entry for the second request will show IP2.

Plugin Details

Logging fields which may be used to obtain details of plugins involved in the transaction.

FieldSourceDescription
piidProxy PluginPlugin ID for the current transaction. This is set for plugin driven transactions via TSHttpConnectWithPluginId().
pitagProxy PluginPlugin tag for the current transaction. This is set for plugin driven transactions via TSHttpConnectWithPluginId().
cqintClient RequestIf a request was generated internally (via a plugin), then this has a value of 1, otherwise 0. This can be useful when tracking internal only requests, such as those generated by the authproxy plugin.

Protocols and Versions

These logging fields may be used to determine which protocols and/or versions were in effect for a given event.

FieldSourceDescription
cqhvClient RequestClient request HTTP version.
cqpvClient RequestClient request protocol and version.
csshvCached Proxy ResponseOrigin server’s HTTP version from cached version of the document in Traffic Server proxy cache.
sshvOrigin ResponseOrigin server’s response HTTP version.

Request Details

The following logging fields are used to obtain the actual HTTP request details.

FieldSourceDescription
cqtxClient RequestThe full HTTP client request text, minus headers, e.g. GET http://www.company.com HTTP/1.0. In reverse proxy mode, Traffic Server logs rewritten/mapped URL (according to the rules in remap.config), not the pristine/unmapped URL.

SSL / Encryption

Fields which expose the use, or lack thereof, of specific SSL and encryption features.

FieldSourceDescription
cqsslClient RequestSSL client request status indicates if this client connection is over SSL.
cqssrClient RequestSSL session ticket reused status; indicates if the current request hit the SSL session ticket and avoided a full SSL handshake.
cqssvClient RequestSSL version used to communicate with the client.
cqsscClient RequestSSL Cipher used by Traffic Server to communicate with the client.
pqsslProxy RequestIndicates whether the connection from Traffic Server to the origin was over SSL or not.

Status Codes

These log fields provide a variety of status codes, some numeric and some as strings, relating to client, proxy, and origin transactions.

FieldSourceDescription
cfscClient RequestFinish status code specifying whether the client request to Traffic Server was successfully completed (FIN) or interrupted (INTR).
cssscCached Proxy ResponseHTTP response status code of the origin server response, as cached by Traffic Server.
pfscProxy RequestFinish status code specifying whether the proxy request from Traffic Server to the origin server was successfully completed (FIN), interrupted (INTR), or timed out (TIMEOUT).
prrpProxy ResponseHTTP response reason phrase sent by Traffic Server proxy to the client.
psscProxy ResponseHTTP response status code sent by Traffic Server proxy to the client.
ssscOrigin ResponseHTTP response status code sent by the origin server to the Traffic Server proxy.

TCP Details

The following logging fields reveal information about the TCP layer of client, proxy, and origin server connections.

FieldSourceDescription
cqtrClient RequestTCP reused status of the connection between the client and Traffic Server proxy, indicating whether the request was delivered through an already established connection.
cqmptClient RequestIndicates the MPTCP state of the connection. -1 means MPTCP was not enabled on the listening port, whereas 0 and 1 indicates whether MPTCP was successfully negotiated or not.

Timestamps and Durations

The logging fields expose a variety of timing related information about client, proxy, and origin transactions. Variants of some of the fields provide timing resolution of the same underlying detail in milliseconds and seconds (both fractional and rounded-down integers). These variants are particularly useful in accommodating the emulation of other HTTP proxy softwares’ logging formats.

Other fields in this category provide variously formatted timestamps of particular events within the current transaction (e.g. the time at which a client request was received by Traffic Server).

FieldSourceDescription
cqtdClient RequestClient request timestamp. Specifies the date of the client request in the format YYYY-MM-DD (four digit year, two digit month, two digit day - with leading zeroes as necessary for the latter two).
cqtnClient RequestClient request timestamp in the Netscape timestamp format.
cqtqClient RequestThe time at which the client request was received expressed as fractional (floating point) seconds since midnight January 1, 1970 UTC (epoch), with millisecond resolution.
cqtsClient RequestSame as cqtq, but as an integer without sub-second resolution.
cqthClient RequestSame as cqts, but represented in hexadecimal.
cqttClient RequestClient request timestamp in the 24-hour format hh:mm:ss (two digit hour, minutes, and seconds - with leading zeroes as necessary).
cratOrigin ResponseRetry-After time in seconds if specified in the origin server response.
msProxyTimestamp in milliseconds of a specific milestone for this request. See note below about specifying which milestone to use.
msdmsProxyDifference in milliseconds between the timestamps of two milestones. See note below about specifying which milestones to use.
stmsProxy-Origin ConnectionTime (in milliseconds) spent accessing the origin server. Measured from the time the connection between proxy and origin is established to the time it was closed.
stmshProxy-Origin ConnectionSame as stms, but represented in hexadecimal.
stmsfProxy-Origin ConnectionSame as stms, but in fractional (floating point) seconds.
stsProxy-Origin ConnectionSame as stms, but in integer seconds (no sub-second precision).
ttmsClient-Proxy ConnectionTime in milliseconds spent by Traffic Server processing the entire client request. Measured from the time the connection between the client and Traffic Server proxy was established until the last byte of the proxy response was delivered to the client.
ttmshClient-Proxy ConnectionSame as ttms, but represented in hexadecimal.
ttmsfClient-Proxy ConnectionSame as ttms, but in fraction (floating point) seconds.
ttsClient RequestSame as ttms, but in integer seconds (no sub-second precision).

Note

Logging fields for transaction milestones require specifying which of the milestones to use. Similar to how header logging fields are used, these log fields take the milestone name(s) in between curly braces, immediately before the logging field name, as so:

  1. %<{Milestone field name}ms>
  2. %<{Milestone field name1-Milestone field name2}msdms>

For more information on transaction milestones in Traffic Server, refer to the documentation on TSHttpTxnMilestoneGet().

URLs, Schemes, and Paths

These log fields allow capture of URLs, or components (such as schemes and paths), from transactions processed by Traffic Server.

FieldSourceDescription
cquProxy RequestURI of the client request to Traffic Server (a subset of cqtx). In reverse proxy mode, Traffic Server logs the rewritten/mapped URL (according to the rules in remap.config), not the pristine/unmapped URL.
cqucClient RequestCanonical URL from the client request to Traffic Server. This field differs from cqu by having its contents URL-escaped (spaces and various other characters are replaced by percent-escaped entity codes).
cqupProxy RequestPath component from the remapped client request.
cqusClient RequestURL scheme from the client request.
cquucClient RequestCanonical (prior to remapping) effective URL from client request.
cquupClient RequestCanonical (prior to remapping) path component from the client request. Compare with cqup.
cquuhClient RequestUnmapped URL host from the client request.

Log Field Slicing

It is sometimes desirable to slice a log field to limit the length of a given log field’s output.

Log Field slicing can be specified as below:

  1. %<field[start:end]>
  2. %<{field}container[start:end]>

Omitting the slice notation defaults to the entire log field.

Slice notation only applies to a log field that is of type string and can not be applied to IPs or timestamp which are converted to string from integer.

The below slice specifiers are allowed.

[start:end]

Log field value from start through end-1

[start:]

Log field value from start through the rest of the string

[:end]

Log field value from the beginning through end-1

[:]

Default - entire Log field

Some examples below

  1. '%<cqup>' // the whole characters of <cqup>.
  2. '%<cqup>[:]' // the whole characters of <cqup>.
  3. '%<cqup[0:30]>' // the first 30 characters of <cqup>.
  4. '%<cqup[-10:]>' // the last 10 characters of <cqup>.
  5. '%<cqup[:-5]>' // everything except the last 5 characters of <cqup>.