Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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 <xdong@csumb.edu> Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru> Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
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

+11
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

+11
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

+11
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

+11
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

+11
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

+11
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

+6
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

+11
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

+11
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

+11
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>

doc/src/sgml/ref/pg_dumpall.sgml

+11
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,17 @@ PostgreSQL documentation
695695
</para>
696696
</listitem>
697697
</varlistentry>
698+
699+
<varlistentry>
700+
<term><envar>PG_COLOR</envar></term>
701+
<listitem>
702+
<para>
703+
Specifies whether to use color in diagnostics messages. Possible values
704+
are <literal>always</literal>, <literal>auto</literal>,
705+
<literal>never</literal>.
706+
</para>
707+
</listitem>
708+
</varlistentry>
698709
</variablelist>
699710

700711
<para>

doc/src/sgml/ref/pg_isready.sgml

+7
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ PostgreSQL documentation
164164
also uses the environment variables supported by <application>libpq</application>
165165
(see <xref linkend="libpq-envars"/>).
166166
</para>
167+
168+
<para>
169+
The environment variable <envar>PG_COLOR</envar> specifies whether to use
170+
color in diagnostics messages. Possible values are
171+
<literal>always</literal>, <literal>auto</literal>,
172+
<literal>never</literal>.
173+
</para>
167174
</refsect1>
168175

169176
<refsect1 id="app-pg-isready-notes">

doc/src/sgml/ref/pg_receivewal.sgml

+6
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ PostgreSQL documentation
408408
(see <xref linkend="libpq-envars"/>).
409409
</para>
410410

411+
<para>
412+
The environment variable <envar>PG_COLOR</envar> specifies whether to use
413+
color in diagnostics messages. Possible values are
414+
<literal>always</literal>, <literal>auto</literal>,
415+
<literal>never</literal>.
416+
</para>
411417
</refsect1>
412418

413419
<refsect1>

doc/src/sgml/ref/pg_recvlogical.sgml

+7
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@ PostgreSQL documentation
397397
uses the environment variables supported by <application>libpq</application>
398398
(see <xref linkend="libpq-envars"/>).
399399
</para>
400+
401+
<para>
402+
The environment variable <envar>PG_COLOR</envar> specifies whether to use
403+
color in diagnostics messages. Possible values are
404+
<literal>always</literal>, <literal>auto</literal>,
405+
<literal>never</literal>.
406+
</para>
400407
</refsect1>
401408

402409
<refsect1>

doc/src/sgml/ref/pg_resetwal.sgml

+17
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,23 @@ PostgreSQL documentation
320320
</variablelist>
321321
</refsect1>
322322

323+
<refsect1>
324+
<title>Environment</title>
325+
326+
<variablelist>
327+
<varlistentry>
328+
<term><envar>PG_COLOR</envar></term>
329+
<listitem>
330+
<para>
331+
Specifies whether to use color in diagnostics messages. Possible values
332+
are <literal>always</literal>, <literal>auto</literal>,
333+
<literal>never</literal>.
334+
</para>
335+
</listitem>
336+
</varlistentry>
337+
</variablelist>
338+
</refsect1>
339+
323340
<refsect1>
324341
<title>Notes</title>
325342

doc/src/sgml/ref/pg_restore.sgml

+11
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,17 @@
822822
</para>
823823
</listitem>
824824
</varlistentry>
825+
826+
<varlistentry>
827+
<term><envar>PG_COLOR</envar></term>
828+
<listitem>
829+
<para>
830+
Specifies whether to use color in diagnostics messages. Possible values
831+
are <literal>always</literal>, <literal>auto</literal>,
832+
<literal>never</literal>.
833+
</para>
834+
</listitem>
835+
</varlistentry>
825836
</variablelist>
826837

827838
<para>

doc/src/sgml/ref/pg_rewind.sgml

+7
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ PostgreSQL documentation
234234
<application>pg_rewind</application> also uses the environment variables
235235
supported by <application>libpq</application> (see <xref linkend="libpq-envars"/>).
236236
</para>
237+
238+
<para>
239+
The environment variable <envar>PG_COLOR</envar> specifies whether to use
240+
color in diagnostics messages. Possible values are
241+
<literal>always</literal>, <literal>auto</literal>,
242+
<literal>never</literal>.
243+
</para>
237244
</refsect1>
238245

239246
<refsect1>

doc/src/sgml/ref/pg_waldump.sgml

+26
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,32 @@ PostgreSQL documentation
206206
</para>
207207
</refsect1>
208208

209+
<refsect1>
210+
<title>Environment</title>
211+
212+
<variablelist>
213+
<varlistentry>
214+
<term><envar>PGDATA</envar></term>
215+
<listitem>
216+
<para>
217+
Data directory; see also the <option>-p</option> option.
218+
</para>
219+
</listitem>
220+
</varlistentry>
221+
222+
<varlistentry>
223+
<term><envar>PG_COLOR</envar></term>
224+
<listitem>
225+
<para>
226+
Specifies whether to use color in diagnostics messages. Possible values
227+
are <literal>always</literal>, <literal>auto</literal>,
228+
<literal>never</literal>.
229+
</para>
230+
</listitem>
231+
</varlistentry>
232+
</variablelist>
233+
</refsect1>
234+
209235
<refsect1>
210236
<title>Notes</title>
211237
<para>

doc/src/sgml/ref/psql-ref.sgml

+11
Original file line numberDiff line numberDiff line change
@@ -4333,6 +4333,17 @@ $endif
43334333
</listitem>
43344334
</varlistentry>
43354335

4336+
<varlistentry>
4337+
<term><envar>PG_COLOR</envar></term>
4338+
<listitem>
4339+
<para>
4340+
Specifies whether to use color in diagnostics messages. Possible values
4341+
are <literal>always</literal>, <literal>auto</literal>,
4342+
<literal>never</literal>.
4343+
</para>
4344+
</listitem>
4345+
</varlistentry>
4346+
43364347
<varlistentry>
43374348
<term><envar>PSQL_EDITOR</envar></term>
43384349
<term><envar>EDITOR</envar></term>

doc/src/sgml/ref/reindexdb.sgml

+11
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,17 @@ PostgreSQL documentation
352352
</para>
353353
</listitem>
354354
</varlistentry>
355+
356+
<varlistentry>
357+
<term><envar>PG_COLOR</envar></term>
358+
<listitem>
359+
<para>
360+
Specifies whether to use color in diagnostics messages. Possible values
361+
are <literal>always</literal>, <literal>auto</literal>,
362+
<literal>never</literal>.
363+
</para>
364+
</listitem>
365+
</varlistentry>
355366
</variablelist>
356367

357368
<para>

doc/src/sgml/ref/vacuumdb.sgml

+11
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,17 @@ PostgreSQL documentation
451451
</para>
452452
</listitem>
453453
</varlistentry>
454+
455+
<varlistentry>
456+
<term><envar>PG_COLOR</envar></term>
457+
<listitem>
458+
<para>
459+
Specifies whether to use color in diagnostics messages. Possible values
460+
are <literal>always</literal>, <literal>auto</literal>,
461+
<literal>never</literal>.
462+
</para>
463+
</listitem>
464+
</varlistentry>
454465
</variablelist>
455466

456467
<para>

src/backend/access/transam/xlog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4761,7 +4761,7 @@ ReadControlFile(void)
47614761
void
47624762
UpdateControlFile(void)
47634763
{
4764-
update_controlfile(DataDir, NULL, ControlFile, true);
4764+
update_controlfile(DataDir, ControlFile, true);
47654765
}
47664766

47674767
/*

0 commit comments

Comments
 (0)