Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mod_log_config: Add log_formatter support and a JSON log_formatter #429

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 32 additions & 0 deletions include/httpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,38 @@ AP_DECLARE(char *) ap_escape_html2(apr_pool_t *p, const char *s, int toasc)
AP_DECLARE(char *) ap_escape_logitem(apr_pool_t *p, const char *str)
AP_FN_ATTR_NONNULL((1));

/**
* Apply JSON escaping to a UTF string. Invalid UTF8 character sequences
* are replaced by the U+FFFD replacement character.
* @param dest The destination buffer, can be NULL
* @param src The original buffer
* @param srclen The length of the original buffer. Pass APR_ESCAPE_STRING
* for a NUL terminated string.
* @param quote If non zero, surround the string with quotes, and if the
* string is NULL, return the string "NULL".
* @param len If present, returns the length of the string
* @return APR_SUCCESS, or APR_NOTFOUND if the string resulted in no
* modification, APR_EINVAL if bad UTF8 is detected. In all cases valid
* UTF8 is returned.
*/
APR_DECLARE(apr_status_t) ap_escape_json(char *dest, const char *src,
apr_ssize_t srclen, int quote, apr_size_t *len);

/**
* Apply JSON escaping to a UTF string. Invalid UTF8 character sequences
* are replaced by the U+FFFD replacement character.
* @param p Pool to allocate from
* @param src The original buffer
* @param srclen The length of the original buffer. Pass APR_ESCAPE_STRING
* for a NUL terminated string.
* @param quote If non zero, surround the string with quotes, and if the
* string is NULL, return the string "NULL".
* @return A zero padded buffer allocated from the pool on success, or
* NULL if src was NULL.
*/
APR_DECLARE(const char *) ap_pescape_json(apr_pool_t *p, const char *src,
apr_ssize_t srclen, int quote);

/**
* Escape a string for logging into the error log (without a pool)
* @param dest The buffer to write to
Expand Down
Loading