Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc8d415

Browse files
committed
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error printing) systems used throughout the command-line programs. Features: - Program name is automatically prefixed. - Message string does not end with newline. This removes a common source of inconsistencies and omissions. - Additionally, a final newline is automatically stripped, simplifying use of PQerrorMessage() etc., another common source of mistakes. - I converted error message strings to use %m where possible. - As a result of the above several points, more translatable message strings can be shared between different components and between frontends and backend, without gratuitous punctuation or whitespace differences. - There is support for setting a "log level". This is not meant to be user-facing, but can be used internally to implement debug or verbose modes. - Lazy argument evaluation, so no significant overhead if logging at some level is disabled. - Some color in the messages, similar to gcc and clang. Set PG_COLOR=auto to try it out. Some colors are predefined, but can be customized by setting PG_COLORS. - Common files (common/, fe_utils/, etc.) can handle logging much more simply by just using one API without worrying too much about the context of the calling program, requiring callbacks, or having to pass "progname" around everywhere. - Some programs called setvbuf() to make sure that stderr is unbuffered, even on Windows. But not all programs did that. This is now done centrally. Soft goals: - Reduces vertical space use and visual complexity of error reporting in the source code. - Encourages more deliberate classification of messages. For example, in some cases it wasn't clear without analyzing the surrounding code whether a message was meant as an error or just an info. - Concepts and terms are vaguely aligned with popular logging frameworks such as log4j and Python logging. This is all just about printing stuff out. Nothing affects program flow (e.g., fatal exits). The uses are just too varied to do that. Some existing code had wrappers that do some kind of print-and-exit, and I adapted those. I tried to keep the output mostly the same, but there is a lot of historical baggage to unwind and special cases to consider, and I might not always have succeeded. One significant change is that pg_rewind used to write all error messages to stdout. That is now changed to stderr. Reviewed-by: Donald Dong <[email protected]> Reviewed-by: Arthur Zakirov <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/[email protected]
1 parent b4cc19a commit cc8d415

File tree

132 files changed

+2555
-2686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+2555
-2686
lines changed

doc/src/sgml/ref/clusterdb.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ PostgreSQL documentation
274274
</para>
275275
</listitem>
276276
</varlistentry>
277+
278+
<varlistentry>
279+
<term><envar>PG_COLOR</envar></term>
280+
<listitem>
281+
<para>
282+
Specifies whether to use color in diagnostics messages. Possible values
283+
are <literal>always</literal>, <literal>auto</literal>,
284+
<literal>never</literal>.
285+
</para>
286+
</listitem>
287+
</varlistentry>
277288
</variablelist>
278289

279290
<para>

doc/src/sgml/ref/createdb.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,17 @@ PostgreSQL documentation
322322
</para>
323323
</listitem>
324324
</varlistentry>
325+
326+
<varlistentry>
327+
<term><envar>PG_COLOR</envar></term>
328+
<listitem>
329+
<para>
330+
Specifies whether to use color in diagnostics messages. Possible values
331+
are <literal>always</literal>, <literal>auto</literal>,
332+
<literal>never</literal>.
333+
</para>
334+
</listitem>
335+
</varlistentry>
325336
</variablelist>
326337

327338
<para>

doc/src/sgml/ref/createuser.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ PostgreSQL documentation
400400
</para>
401401
</listitem>
402402
</varlistentry>
403+
404+
<varlistentry>
405+
<term><envar>PG_COLOR</envar></term>
406+
<listitem>
407+
<para>
408+
Specifies whether to use color in diagnostics messages. Possible values
409+
are <literal>always</literal>, <literal>auto</literal>,
410+
<literal>never</literal>.
411+
</para>
412+
</listitem>
413+
</varlistentry>
403414
</variablelist>
404415

405416
<para>

doc/src/sgml/ref/dropdb.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ PostgreSQL documentation
228228
</para>
229229
</listitem>
230230
</varlistentry>
231+
232+
<varlistentry>
233+
<term><envar>PG_COLOR</envar></term>
234+
<listitem>
235+
<para>
236+
Specifies whether to use color in diagnostics messages. Possible values
237+
are <literal>always</literal>, <literal>auto</literal>,
238+
<literal>never</literal>.
239+
</para>
240+
</listitem>
241+
</varlistentry>
231242
</variablelist>
232243

233244
<para>

doc/src/sgml/ref/dropuser.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,17 @@ PostgreSQL documentation
220220
</para>
221221
</listitem>
222222
</varlistentry>
223+
224+
<varlistentry>
225+
<term><envar>PG_COLOR</envar></term>
226+
<listitem>
227+
<para>
228+
Specifies whether to use color in diagnostics messages. Possible values
229+
are <literal>always</literal>, <literal>auto</literal>,
230+
<literal>never</literal>.
231+
</para>
232+
</listitem>
233+
</varlistentry>
223234
</variablelist>
224235

225236
<para>

doc/src/sgml/ref/initdb.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,17 @@ PostgreSQL documentation
461461
</listitem>
462462
</varlistentry>
463463

464+
<varlistentry>
465+
<term><envar>PG_COLOR</envar></term>
466+
<listitem>
467+
<para>
468+
Specifies whether to use color in diagnostics messages. Possible values
469+
are <literal>always</literal>, <literal>auto</literal>,
470+
<literal>never</literal>.
471+
</para>
472+
</listitem>
473+
</varlistentry>
474+
464475
<varlistentry>
465476
<term><envar>TZ</envar></term>
466477

doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,12 @@ PostgreSQL documentation
687687
(see <xref linkend="libpq-envars"/>).
688688
</para>
689689

690+
<para>
691+
The environment variable <envar>PG_COLOR</envar> specifies whether to use
692+
color in diagnostics messages. Possible values are
693+
<literal>always</literal>, <literal>auto</literal>,
694+
<literal>never</literal>.
695+
</para>
690696
</refsect1>
691697

692698
<refsect1>

doc/src/sgml/ref/pg_checksums.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ PostgreSQL documentation
173173
</para>
174174
</listitem>
175175
</varlistentry>
176+
177+
<varlistentry>
178+
<term><envar>PG_COLOR</envar></term>
179+
<listitem>
180+
<para>
181+
Specifies whether to use color in diagnostics messages. Possible values
182+
are <literal>always</literal>, <literal>auto</literal>,
183+
<literal>never</literal>.
184+
</para>
185+
</listitem>
186+
</varlistentry>
176187
</variablelist>
177188
</refsect1>
178189

doc/src/sgml/ref/pg_controldata.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ PostgreSQL documentation
6868
</para>
6969
</listitem>
7070
</varlistentry>
71+
72+
<varlistentry>
73+
<term><envar>PG_COLOR</envar></term>
74+
<listitem>
75+
<para>
76+
Specifies whether to use color in diagnostics messages. Possible values
77+
are <literal>always</literal>, <literal>auto</literal>,
78+
<literal>never</literal>.
79+
</para>
80+
</listitem>
81+
</varlistentry>
7182
</variablelist>
7283
</refsect1>
7384
</refentry>

doc/src/sgml/ref/pg_dump.sgml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,17 @@ PostgreSQL documentation
12241224
</listitem>
12251225

12261226
</varlistentry>
1227+
1228+
<varlistentry>
1229+
<term><envar>PG_COLOR</envar></term>
1230+
<listitem>
1231+
<para>
1232+
Specifies whether to use color in diagnostics messages. Possible values
1233+
are <literal>always</literal>, <literal>auto</literal>,
1234+
<literal>never</literal>.
1235+
</para>
1236+
</listitem>
1237+
</varlistentry>
12271238
</variablelist>
12281239

12291240
<para>

0 commit comments

Comments
 (0)