Skip to content

Commit

Permalink
mod_log_config: json formatter: Updated manual and some fixes from re…
Browse files Browse the repository at this point in the history
…view
  • Loading branch information
thomasmey committed Dec 21, 2024
1 parent 753f524 commit d77a1fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions changes-entries/mod_log_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*) mod_log_config: Add support for output log in JSON format [Thomas Meyer]
14 changes: 13 additions & 1 deletion docs/manual/mod/mod_log_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@
<description>Sets filename and format of log file</description>
<syntax>CustomLog <var>file</var>|<var>pipe</var>|<var>provider</var>
<var>format</var>|<var>nickname</var>
[formatter=json[,short]]
[env=[!]<var>environment-variable</var>|
expr=<var>expression</var>]</syntax>
<contextlist><context>server config</context><context>virtual host</context>
Expand Down Expand Up @@ -525,7 +526,18 @@ CustomLog "logs/access_log" common
CustomLog "logs/access_log" "%h %l %u %t \"%r\" %&gt;s %b"
</highlight>

<p>The third argument is optional and controls whether or
<p>The third argument is optional and controls whether to use a special
formatter to create the log records. Currently only the formatter "json" is
supported which will create all log records according to RFC8259 and
each printed log record will be a JSON object.
The optional formatter option "short" make the json formatter output short
JSON key names. The JSON key names in short format are directly derived
from the format string, i.e. "%s" will result in a JSON of {"s":"304"}.
If the "short" option is not specified long JSON key names will be used for
better readability in JSON object, e.g. {"statusCode":"304"}
</p>

<p>The last argument is optional and controls whether or
not to log a particular request. The condition can be the
presence or absence (in the case of a '<code>env=!<var>name</var></code>'
clause) of a particular variable in the server
Expand Down
10 changes: 5 additions & 5 deletions modules/loggers/mod_log_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ static config_log_state *open_config_log(server_rec *s, apr_pool_t *p,
if (cls->log_writer_data == NULL)
return NULL;

/* sort log_format_items array, to help json formatter in gruppenwechsel */
/* sort log_format_items array, to help json formatter in control break */
if (cls->log_formatter == ap_json_log_formatter /* sort_log_format_items */ ) {
/* no valid cls->format given in format string,
use default_format, if any valid */
Expand Down Expand Up @@ -1883,7 +1883,7 @@ static ap_log_formatted_data * ap_json_log_formatter( request_rec *r,
*
* as multiple same tags with different arguments can exist,
* the log_format_item is sorted before, so we can easily check for
* gruppenwechsel
* control break (https://en.wikipedia.org/wiki/Control_break)
*/
if(items[i].arg != NULL && strlen(items[i].arg) > 0) {
/* start sub object */
Expand All @@ -1894,7 +1894,7 @@ static ap_log_formatted_data * ap_json_log_formatter( request_rec *r,
continue;
}

/* is gruppenwechsel */
/* is control break */
if(j > i && strcmp(items[j].tag, items[i].tag) != 0) {
break;
}
Expand Down Expand Up @@ -2025,7 +2025,7 @@ static ap_log_formatted_data * ap_json_log_formatter( request_rec *r,
*
* as multiple same tags with different arguments can exist,
* the log_format_item is sorted before, so we can easily check for
* gruppenwechsel
* control break
*/
if(items[i].arg != NULL && strlen(items[i].arg) > 0) {
/* TODO: or allocate once at the begining and use apr_array_clear here? */
Expand All @@ -2041,7 +2041,7 @@ static ap_log_formatted_data * ap_json_log_formatter( request_rec *r,
continue;
}

/* is gruppenwechsel */
/* is control break */
if(j > i && strcmp(items[j].tag, items[i].tag) != 0) {
break;
}
Expand Down

0 comments on commit d77a1fc

Please sign in to comment.