]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: log: add +json encoding option
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 22 Apr 2024 12:40:04 +0000 (14:40 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 26 Apr 2024 16:39:32 +0000 (18:39 +0200)
commit3f7c8387c02ee4bca75197ef4e30fc38fdfbb858
tree67554dc00918ef8f52e3615fd73074254224de37
parentb7c3d8c87cafc568bd9cfa1eb0a283fe931623ac
MINOR: log: add +json encoding option

In this patch, we add the "+json" log format option that can be set
globally or per log format node.

What it does, it that it sets the LOG_OPT_ENCODE_JSON flag for the
current context which is provided to all lf_* log building function.

This way, all lf_* are now aware of this option and try to comply with
JSON specification when the option is set.

If the option is set globally, then sess_build_logline() will produce a
map-like object with key=val pairs for named logformat nodes.
(logformat nodes that don't have a name are simply ignored).

Example:
  log-format "%{+json}o %[int(4)] test %(named_field)[str(ok)]"

Will produce:
  {"named_field": "ok"}

If the option isn't set globally, but on a specific node instead, then
only the value will be encoded according to JSON specification.

Example:
  log-format "{ \"manual_key\": %(named_field){+json}[bool(true)] }"

Will produce:
  {"manual_key": true}

When the option is set, +E option will be ignored, and partial numerical
values (ie: because of logasap) will be encoded as-is.
doc/configuration.txt
include/haproxy/log-t.h
src/log.c