mirror of
https://github.com/postgres/postgres.git
synced 2025-08-05 07:41:25 +03:00
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 inac7c807
,bed6ed3
,8b76f89
and2d77d83
for the backend parts, and72b76f7
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
This commit is contained in:
@@ -6,7 +6,7 @@ use warnings;
|
||||
|
||||
use PostgreSQL::Test::Cluster;
|
||||
use PostgreSQL::Test::Utils;
|
||||
use Test::More tests => 10;
|
||||
use Test::More tests => 14;
|
||||
use Time::HiRes qw(usleep);
|
||||
|
||||
# Extract the file name of a $format from the contents of
|
||||
@@ -65,7 +65,7 @@ $node->init();
|
||||
$node->append_conf(
|
||||
'postgresql.conf', qq(
|
||||
logging_collector = on
|
||||
log_destination = 'stderr, csvlog'
|
||||
log_destination = 'stderr, csvlog, jsonlog'
|
||||
# these ensure stability of test results:
|
||||
log_rotation_age = 0
|
||||
lc_messages = 'C'
|
||||
@@ -96,11 +96,13 @@ note "current_logfiles = $current_logfiles";
|
||||
like(
|
||||
$current_logfiles,
|
||||
qr|^stderr log/postgresql-.*log
|
||||
csvlog log/postgresql-.*csv$|,
|
||||
csvlog log/postgresql-.*csv
|
||||
jsonlog log/postgresql-.*json$|,
|
||||
'current_logfiles is sane');
|
||||
|
||||
check_log_pattern('stderr', $current_logfiles, 'division by zero', $node);
|
||||
check_log_pattern('csvlog', $current_logfiles, 'division by zero', $node);
|
||||
check_log_pattern('stderr', $current_logfiles, 'division by zero', $node);
|
||||
check_log_pattern('csvlog', $current_logfiles, 'division by zero', $node);
|
||||
check_log_pattern('jsonlog', $current_logfiles, 'division by zero', $node);
|
||||
|
||||
# Sleep 2 seconds and ask for log rotation; this should result in
|
||||
# output into a different log file name.
|
||||
@@ -122,13 +124,15 @@ note "now current_logfiles = $new_current_logfiles";
|
||||
like(
|
||||
$new_current_logfiles,
|
||||
qr|^stderr log/postgresql-.*log
|
||||
csvlog log/postgresql-.*csv$|,
|
||||
csvlog log/postgresql-.*csv
|
||||
jsonlog log/postgresql-.*json$|,
|
||||
'new current_logfiles is sane');
|
||||
|
||||
# Verify that log output gets to this file, too
|
||||
$node->psql('postgres', 'fee fi fo fum');
|
||||
|
||||
check_log_pattern('stderr', $new_current_logfiles, 'syntax error', $node);
|
||||
check_log_pattern('csvlog', $new_current_logfiles, 'syntax error', $node);
|
||||
check_log_pattern('stderr', $new_current_logfiles, 'syntax error', $node);
|
||||
check_log_pattern('csvlog', $new_current_logfiles, 'syntax error', $node);
|
||||
check_log_pattern('jsonlog', $new_current_logfiles, 'syntax error', $node);
|
||||
|
||||
$node->stop();
|
||||
|
Reference in New Issue
Block a user