changeset 2540:b686736680e3

Documented escaping rules in log_format.
author Yaroslav Zhuravlev <yar@nginx.com>
date Tue, 12 May 2020 22:06:12 +0100
parents 5a5a791b3166
children 0e6bbd8138c4
files xml/en/docs/http/ngx_http_log_module.xml xml/en/docs/stream/ngx_stream_log_module.xml xml/ru/docs/http/ngx_http_log_module.xml xml/ru/docs/stream/ngx_stream_log_module.xml
diffstat 4 files changed, 107 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/xml/en/docs/http/ngx_http_log_module.xml
+++ b/xml/en/docs/http/ngx_http_log_module.xml
@@ -10,7 +10,7 @@
 <module name="Module ngx_http_log_module"
         link="/en/docs/http/ngx_http_log_module.html"
         lang="en"
-        rev="19">
+        rev="20">
 
 <section id="summary">
 
@@ -210,6 +210,33 @@ in variables, by default, <literal>defau
 The <literal>none</literal> value (1.13.10) disables escaping.
 </para>
 
+<para id="log_format_escape_default">
+For <literal>default</literal> escaping,
+characters “<literal>"</literal>”, “<literal>\</literal>”,
+and other characters with values less than 32 (0.7.0) or above 126 (1.1.6)
+are escaped as “<literal>\xXX</literal>”.
+If the variable value is not found,
+a hyphen (“<literal>-</literal>”) will be logged.
+</para>
+
+<para id="log_format_escape_json">
+For <literal>json</literal> escaping,
+all characters not allowed
+in JSON <link url="https://tools.ietf.org/html/rfc8259#section-7">strings</link>
+will be escaped:
+characters “<literal>"</literal>” and
+“<literal>\</literal>” are escaped as
+“<literal>\"</literal>” and “<literal>\\</literal>”,
+characters with values less than 32 are escaped as
+“<literal>\n</literal>”,
+“<literal>\r</literal>”,
+“<literal>\t</literal>”,
+“<literal>\b</literal>”,
+“<literal>\f</literal>”, or
+“<literal>\u00XX</literal>”.
+
+</para>
+
 <para>
 The log format can contain common variables, and variables that
 exist only at the time of a log write:
--- a/xml/en/docs/stream/ngx_stream_log_module.xml
+++ b/xml/en/docs/stream/ngx_stream_log_module.xml
@@ -9,7 +9,7 @@
 <module name="Module ngx_stream_log_module"
         link="/en/docs/stream/ngx_stream_log_module.html"
         lang="en"
-        rev="6">
+        rev="7">
 
 <section id="summary">
 
@@ -177,6 +177,32 @@ in variables, by default, <literal>defau
 The <literal>none</literal> parameter (1.13.10) disables escaping.
 </para>
 
+<para id="log_format_escape_default">
+For <literal>default</literal> escaping,
+characters “<literal>"</literal>”, “<literal>\</literal>”,
+and other characters with values less than 32 or above 126
+are escaped as “<literal>\xXX</literal>”.
+If the variable value is not found,
+a hyphen (“<literal>-</literal>”) will be logged.
+</para>
+
+<para id="log_format_escape_json">
+For <literal>json</literal> escaping,
+all characters not allowed
+in JSON <link url="https://tools.ietf.org/html/rfc8259#section-7">strings</link>
+will be escaped:
+characters “<literal>"</literal>” and
+“<literal>\</literal>” are escaped as
+“<literal>\"</literal>” and “<literal>\\</literal>”,
+characters with values less than 32 are escaped as
+“<literal>\n</literal>”,
+“<literal>\r</literal>”,
+“<literal>\t</literal>”,
+“<literal>\b</literal>”,
+“<literal>\f</literal>”, or
+“<literal>\u00XX</literal>”.
+</para>
+
 </directive>
 
 
--- a/xml/ru/docs/http/ngx_http_log_module.xml
+++ b/xml/ru/docs/http/ngx_http_log_module.xml
@@ -10,7 +10,7 @@
 <module name="Модуль ngx_http_log_module"
         link="/ru/docs/http/ngx_http_log_module.html"
         lang="ru"
-        rev="19">
+        rev="20">
 
 <section id="summary">
 
@@ -209,6 +209,31 @@ access_log /path/to/access.log combined 
 экранирование символов.
 </para>
 
+<para id="log_format_escape_default">
+При использовании <literal>default</literal>
+символы “<literal>"</literal>”, “<literal>\</literal>”,
+a также символы со значениями меньше 32 (0.7.0) или больше 126 (1.1.6)
+экранируются как “<literal>\xXX</literal>”.
+Если значение переменной не найдено,
+то в качестве значения в лог будет записываться дефис (“<literal>-</literal>”).
+</para>
+
+<para id="log_format_escape_json">
+При использовании <literal>json</literal>
+экранируются все символы, недопустимые
+в JSON <link url="https://tools.ietf.org/html/rfc8259#section-7">строках</link>:
+символы “<literal>"</literal>” и
+“<literal>\</literal>” экранируются как
+“<literal>\"</literal>” и “<literal>\\</literal>”,
+символы со значениями меньше 32 экранируются как
+“<literal>\n</literal>”,
+“<literal>\r</literal>”,
+“<literal>\t</literal>”,
+“<literal>\b</literal>”,
+“<literal>\f</literal>” или
+“<literal>\u00XX</literal>”.
+</para>
+
 <para>
 Кроме общих переменных в формате можно использовать переменные,
 существующие только на момент записи в лог:
--- a/xml/ru/docs/stream/ngx_stream_log_module.xml
+++ b/xml/ru/docs/stream/ngx_stream_log_module.xml
@@ -9,7 +9,7 @@
 <module name="Модуль ngx_stream_log_module"
         link="/ru/docs/stream/ngx_stream_log_module.html"
         lang="ru"
-        rev="6">
+        rev="7">
 
 <section id="summary">
 
@@ -178,6 +178,31 @@ log_format proxy '$remote_addr [$time_lo
 экранирование символов.
 </para>
 
+<para id="log_format_escape_default">
+При использовании <literal>default</literal>
+символы “<literal>"</literal>”, “<literal>\</literal>”,
+a также символы со значениями меньше 32 или больше 126
+экранируются как “<literal>\xXX</literal>”.
+Если значение переменной не найдено,
+то в качестве значения в лог будет записываться дефис (“<literal>-</literal>”).
+</para>
+
+<para id="log_format_escape_json">
+При использовании <literal>json</literal>
+экранируются все символы, недопустимые
+в JSON <link url="https://tools.ietf.org/html/rfc8259#section-7">строках</link>:
+символы “<literal>"</literal>” и
+“<literal>\</literal>” экранируются как
+“<literal>\"</literal>” и “<literal>\\</literal>”,
+символы со значениями меньше 32 экранируются как
+“<literal>\n</literal>”,
+“<literal>\r</literal>”,
+“<literal>\t</literal>”,
+“<literal>\b</literal>”,
+“<literal>\f</literal>” или
+“<literal>\u00XX</literal>”.
+</para>
+
 </directive>