Introduce log_destination=jsonlog
authorMichael Paquier <michael@paquier.xyz>
Mon, 17 Jan 2022 01:16:53 +0000 (10:16 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 17 Jan 2022 01:16:53 +0000 (10:16 +0900)
commitdc686681e0799b12c40f44f85fc5bfd7fed4e57f
tree66654ff9d34f4153810245c2152a6d2ddfbeb761
parent6478896675660402171c97d6307e6e1519250025
Introduce log_destination=jsonlog

"jsonlog" is a new value that can be added to log_destination to provide
logs in the JSON format, with its output written to a file, making it
the third type of destination of this kind, after "stderr" and
"csvlog".  The format is convenient to feed logs to other applications.
There is also a plugin external to core that provided this feature using
the hook in elog.c, but this had to overwrite the output of "stderr" to
work, so being able to do both at the same time was not possible.  The
files generated by this log format are suffixed with ".json", and use
the same rotation policies as the other two formats depending on the
backend configuration.

This takes advantage of the refactoring work done previously in ac7c807,
bed6ed38b76f89 and 2d77d83 for the backend parts, and 72b76f7 for the
TAP tests, making the addition of any new file-based format rather
straight-forward.

The documentation is updated to list all the keys and the values that
can exist in this new format.  pg_current_logfile() also required a
refresh for the new option.

Author: Sehrope Sarkuni, Michael Paquier
Reviewed-by: Nathan Bossart, Justin Pryzby
Discussion: https://postgr.es/m/CAH7T-aqswBM6JWe4pDehi1uOiufqe06DJWaU5=X7dDLyqUExHg@mail.gmail.com
12 files changed:
doc/src/sgml/config.sgml
doc/src/sgml/func.sgml
src/backend/postmaster/syslogger.c
src/backend/utils/adt/misc.c
src/backend/utils/error/Makefile
src/backend/utils/error/elog.c
src/backend/utils/error/jsonlog.c [new file with mode: 0644]
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/bin/pg_ctl/t/004_logrotate.pl
src/include/postmaster/syslogger.h
src/include/utils/elog.h