1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-19 15:49:24 +03:00

Remove not-very-useful early checks of __pg_log_level in logging.h.

Enforce __pg_log_level message filtering centrally in logging.c,
instead of relying on the calling macros to do it.  This is more
reliable (e.g. it works correctly for direct calls to pg_log_generic)
and it saves a percent or so of total code size because we get rid of
so many duplicate checks of __pg_log_level.

This does mean that argument expressions in a logging macro will be
evaluated even if we end up not printing anything.  That seems of
little concern for INFO and higher levels as those messages are printed
by default, and most of our frontend programs don't even offer a way to
turn them off.  I left the unlikely() checks in place for DEBUG
messages, though.

Discussion: https://postgr.es/m/3993549.1649449609@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2022-04-12 13:25:29 -04:00
parent d4f109e4a2
commit 2c9381840f
3 changed files with 24 additions and 40 deletions

View File

@@ -228,6 +228,10 @@ pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
Assert(fmt);
Assert(fmt[strlen(fmt) - 1] != '\n');
/* Do nothing if log level is too low. */
if (level < __pg_log_level)
return;
/*
* Flush stdout before output to stderr, to ensure sync even when stdout
* is buffered.