<commit_before>.. _`RequestLog`: apidocs/index.html?com/linecorp/armeria/common/logging/RequestLog.html
.. _`RequestLogAvailability`: apidocs/index.html?com/linecorp/armeria/common/logging/RequestLogAvailability.html
.. _`RequestContext`: apidocs/index.html?com/linecorp/armeria/common/RequestContext.html

.. _advanced-structured-logging:

Structured logging
==================
Although traditional logging is a useful tool to diagnose the behavior of an application, it has its own
problem; the resulting log messages are not always machine-friendly. This section explains the Armeria API for
retrieving the information collected during request life cycle in a machine-friendly way.

What properties can be retrieved?
---------------------------------
`RequestLog`_ provides all the properties you can retrieve:

+----------------------------------------------------------------------------------------------------+
| Request properties                                                                                 |
+=============================+======================================================================+
| ``requestStartTimeMillis``  | when the request processing started                                  |
+-----------------------------+----------------------------------------------------------------------+
| ``requestDurationNanos``    | the duration took to process the request completely                  |
+-----------------------------+----------------------------------------------------------------------+
| ``requestLength``           | the byte length of the request content                               |
+-----------------------------+----------------------------------------------------------------------+
| ``requestCause``            | the cause of request processing failure (if any)                     |
+-----------------------------+----------------------------------------------------------------------+
| ``sessionProtocol``         | the protocol of the connection (e.g. ``H2C``)                        |
+-----------------------------+----------------------------------------------------------------------+
| ``serializationFormat``     | the serialization format of the content (e.g. ``tbinary``, ``none``) |
+-----------------------------+----------------------------------------------------------------------+
| ``host``                    | the name of the virtual host that serves the request                 |
+-----------------------------+----------------------------------------------------------------------+
| ``method``                  | the method of the request (e.g. ``GET``, ``POST``)                   |
+-----------------------------+----------------------------------------------------------------------+
| ``path``                    | the path of the request (e.g. ``/thrift/foo``)                       |
+-----------------------------+----------------------------------------------------------------------+
| ``requestEnvelope``         | the protocol-dependent envelope object of the request.               |
|                             | ``HttpHeaders`` for HTTP.                                            |
+-----------------------------+----------------------------------------------------------------------+
| ``requestContent``          | the serialization-dependent content object of the request.           |
|                             | ``ThriftCall`` for Thrift. ``null`` otherwise.                       |
+-----------------------------+----------------------------------------------------------------------+

+-----------------------------+----------------------------------------------------------------------+
| Response properties                                                                                |
+=============================+======================================================================+
| ``responseStartTimeMillis`` | when the response processing started                                 |<commit_msg>Add a new property to advanced-structured-logging.rst<commit_after>.. _`RequestLog`: apidocs/index.html?com/linecorp/armeria/common/logging/RequestLog.html
.. _`RequestLogAvailability`: apidocs/index.html?com/linecorp/armeria/common/logging/RequestLogAvailability.html
.. _`RequestContext`: apidocs/index.html?com/linecorp/armeria/common/RequestContext.html

.. _advanced-structured-logging:

Structured logging
==================
Although traditional logging is a useful tool to diagnose the behavior of an application, it has its own
problem; the resulting log messages are not always machine-friendly. This section explains the Armeria API for
retrieving the information collected during request life cycle in a machine-friendly way.

What properties can be retrieved?
---------------------------------
`RequestLog`_ provides all the properties you can retrieve:

+----------------------------------------------------------------------------------------------------+
| Request properties                                                                                 |
+=============================+======================================================================+
| ``requestStartTimeMillis``  | when the request processing started                                  |
+-----------------------------+----------------------------------------------------------------------+
| ``requestDurationNanos``    | the duration took to process the request completely                  |
+-----------------------------+----------------------------------------------------------------------+
| ``requestLength``           | the byte length of the request content                               |
+-----------------------------+----------------------------------------------------------------------+
| ``requestCause``            | the cause of request processing failure (if any)                     |
+-----------------------------+----------------------------------------------------------------------+
| ``sessionProtocol``         | the protocol of the connection (e.g. ``H2C``)                        |
+-----------------------------+----------------------------------------------------------------------+
| ``serializationFormat``     | the serialization format of the content (e.g. ``tbinary``, ``none``) |
+-----------------------------+----------------------------------------------------------------------+
| ``host``                    | the name of the virtual host that serves the request                 |
+-----------------------------+----------------------------------------------------------------------+
| ``method``                  | the method of the request (e.g. ``GET``, ``POST``)                   |
+-----------------------------+----------------------------------------------------------------------+
| ``path``                    | the path of the request (e.g. ``/thrift/foo``)                       |
+-----------------------------+----------------------------------------------------------------------+
| ``query``                   | the query of the request (e.g. ``foo=bar&bar=baz``)                  |
+-----------------------------+----------------------------------------------------------------------+
| ``requestEnvelope``         | the protocol-dependent envelope object of the request.               |
|                             | ``HttpHeaders`` for HTTP.                                            |
+-----------------------------+----------------------------------------------------------------------+
| ``requestContent``          | the serialization-dependent content object of the request.           |
|                             | ``ThriftCall`` for Thrift. ``null`` otherwise.                       |
+-----------------------------+----------------------------------------------------------------------+

+-----------------------------+----------------------------------------------------------------------+
| Response properties                                                                                |
+=============================+======================================================================+
| ``responseStartTimeMillis`` | when the response processing started                                 |
{'fraction_non_alphanumeric': 0.4490707216992518, 'fraction_numerical': 0.0002413709872073377, 'mean_word_length': 0.7794717629375134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7652004', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1188, 'n_words': 375}