Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6165bba

Browse files
committed
Remove 'syslog' GUC variable, and add more logical 'log_destination'
variable to control logoutput location on Unix and Win32.Magnus Hagander
1 parenta12fc7d commit6165bba

File tree

8 files changed

+180
-69
lines changed

8 files changed

+180
-69
lines changed

‎doc/src/sgml/maintenance.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.32 2004/03/15 14:21:30 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.33 2004/04/05 03:02:03 momjian Exp $
33
-->
44

55
<chapter id="maintenance">
@@ -456,7 +456,7 @@ VACUUM
456456
The simplest production-grade approach to managing log output is to
457457
send it all to <application>syslog</> and let
458458
<application>syslog</> deal with file rotation. To do this, set the
459-
configurations parameter <literal>syslog</> to2 (to log to
459+
configurations parameter <literal>log_destination</> to'syslog' (to log to
460460
<application>syslog</> only) in <filename>postgresql.conf</>. Then
461461
you can send a <literal>SIGHUP</literal> signal to the
462462
<application>syslog</> daemon whenever you want to force it to

‎doc/src/sgml/runtime.sgml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.256 2004/03/31 19:59:22 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.257 2004/04/05 03:02:03 momjian Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -469,7 +469,7 @@ psql: could not connect to server: No such file or directory
469469
<programlisting>
470470
# This is a comment
471471
log_connections = yes
472-
syslog =2
472+
log_destination ='syslog'
473473
search_path = '$user, public'
474474
</programlisting>
475475
One parameter is specified per line. The equal sign between name and
@@ -497,7 +497,7 @@ search_path = '$user, public'
497497
A second way to set these configuration parameters is to give them
498498
as a command line option to the <command>postmaster</command>, such as:
499499
<programlisting>
500-
postmaster -c log_connections=yes -csyslog=2
500+
postmaster -c log_connections=yes -clog_destination='syslog'
501501
</programlisting>
502502
Command-line options override any conflicting settings in
503503
<filename>postgresql.conf</filename>.
@@ -1705,27 +1705,26 @@ SET ENABLE_SEQSCAN TO OFF;
17051705
<primary>server log</primary>
17061706
</indexterm>
17071707

1708-
<sect3 id="runtime-config-logging-syslog">
1709-
<title>Syslog</title>
1708+
<sect3 id="runtime-config-logging-where">
1709+
<title>Where to log</title>
17101710

1711-
<indexterm zone="runtime-config-logging-syslog">
1712-
<primary>syslog</primary>
1711+
<indexterm zone="runtime-config-logging-where">
1712+
<primary>where to log</primary>
17131713
</indexterm>
17141714

17151715
<variablelist>
17161716

1717-
<varlistentry id="guc-syslog" xreflabel="syslog">
1718-
<term><varname>syslog</varname> (<type>integer</type>)</term>
1717+
<varlistentry id="guc-log-destination" xreflabel="log_destination">
1718+
<term><varname>log_destination</varname> (<type>string</type>)</term>
17191719
<listitem>
17201720
<para>
1721-
<productname>PostgreSQL</productname> allows the use of
1722-
<systemitem>syslog</systemitem> for logging. If this option is
1723-
set to 1, messages go both to <systemitem>syslog</> and the
1724-
standard output. A setting of 2 sends output only to
1725-
<systemitem>syslog</>. (Some messages will still go to the
1726-
standard output/error.) The default is 0, which means
1727-
<systemitem>syslog</> is off. This option must be set at server
1728-
start.
1721+
<productname>PostgreSQL</productname> supports several methods
1722+
for loggning, including <systemitem>stderr</systemitem> and
1723+
<systemitem>syslog</systemitem>. On Windows,
1724+
<systemitem>eventlog</systemitem> is also supported. Set this
1725+
option to a list of desired log destinations separated by a
1726+
comma. The default is to log to <systemitem>stderr</systemitem>
1727+
only. This option must be set at server start.
17291728
</para>
17301729
</listitem>
17311730
</varlistentry>

‎src/backend/utils/error/elog.c

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.131 2004/03/22 15:34:22 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.132 2004/04/05 03:02:06 momjian Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -70,25 +70,17 @@ ErrorContextCallback *error_context_stack = NULL;
7070
/* GUC parameters */
7171
PGErrorVerbosityLog_error_verbosity=PGERROR_VERBOSE;
7272
char*Log_line_prefix=NULL;/* format for extra log line info */
73+
unsignedintLog_destination;
7374

7475
#ifdefHAVE_SYSLOG
75-
/*
76-
* 0 = only stdout/stderr
77-
* 1 = stdout+stderr and syslog
78-
* 2 = syslog only
79-
* ... in theory anyway
80-
*/
81-
intUse_syslog=0;
8276
char*Syslog_facility;/* openlog() parameters */
8377
char*Syslog_ident;
8478

8579
staticvoidwrite_syslog(intlevel,constchar*line);
86-
87-
#else
88-
89-
#defineUse_syslog 0
90-
#endif/* HAVE_SYSLOG */
91-
80+
#endif
81+
#ifdefWIN32
82+
staticvoidwrite_eventlog(intlevel,constchar*line);
83+
#endif
9284

9385
/*
9486
* ErrorData holds the data accumulated during any one ereport() cycle.
@@ -1005,9 +997,6 @@ write_syslog(int level, const char *line)
1005997

1006998
intlen=strlen(line);
1007999

1008-
if (Use_syslog==0)
1009-
return;
1010-
10111000
if (!openlog_done)
10121001
{
10131002
if (strcasecmp(Syslog_facility,"LOCAL0")==0)
@@ -1099,6 +1088,34 @@ write_syslog(int level, const char *line)
10991088
}
11001089
}
11011090
#endif/* HAVE_SYSLOG */
1091+
#ifdefWIN32
1092+
/*
1093+
* Write a message line to the windows event log
1094+
*/
1095+
staticvoid
1096+
write_eventlog(intlevel,constchar*line)
1097+
{
1098+
staticHANDLEevtHandle=INVALID_HANDLE_VALUE;
1099+
1100+
if (evtHandle==INVALID_HANDLE_VALUE) {
1101+
evtHandle=RegisterEventSource(NULL,"PostgreSQL");
1102+
if (evtHandle==NULL) {
1103+
evtHandle=INVALID_HANDLE_VALUE;
1104+
return;
1105+
}
1106+
}
1107+
1108+
ReportEvent(evtHandle,
1109+
level,
1110+
0,
1111+
0,/* All events are Id 0 */
1112+
NULL,
1113+
1,
1114+
0,
1115+
&line,
1116+
NULL);
1117+
}
1118+
#endif/* WIN32*/
11021119

11031120
/*
11041121
* Format tag info for log lines; append to the provided buffer.
@@ -1344,7 +1361,7 @@ send_message_to_server_log(ErrorData *edata)
13441361

13451362
#ifdefHAVE_SYSLOG
13461363
/* Write to syslog, if enabled */
1347-
if (Use_syslog >=1)
1364+
if (Log_destination&LOG_DESTINATION_SYSLOG)
13481365
{
13491366
intsyslog_level;
13501367

@@ -1381,9 +1398,38 @@ send_message_to_server_log(ErrorData *edata)
13811398
write_syslog(syslog_level,buf.data);
13821399
}
13831400
#endif/* HAVE_SYSLOG */
1384-
1401+
#ifdefWIN32
1402+
if (Log_destination&LOG_DESTINATION_EVENTLOG)
1403+
{
1404+
inteventlog_level;
1405+
switch (edata->elevel)
1406+
{
1407+
caseDEBUG5:
1408+
caseDEBUG4:
1409+
caseDEBUG3:
1410+
caseDEBUG2:
1411+
caseDEBUG1:
1412+
caseLOG:
1413+
caseCOMMERROR:
1414+
caseINFO:
1415+
caseNOTICE:
1416+
eventlog_level=EVENTLOG_INFORMATION_TYPE;
1417+
break;
1418+
caseWARNING:
1419+
eventlog_level=EVENTLOG_WARNING_TYPE;
1420+
break;
1421+
caseERROR:
1422+
caseFATAL:
1423+
casePANIC:
1424+
default:
1425+
eventlog_level=EVENTLOG_ERROR_TYPE;
1426+
break;
1427+
}
1428+
write_eventlog(eventlog_level,buf.data);
1429+
}
1430+
#endif/* WIN32 */
13851431
/* Write to stderr, if enabled */
1386-
if (Use_syslog <=1||whereToSendOutput==Debug)
1432+
if ((Log_destination&LOG_DESTINATION_STDERR)||whereToSendOutput==Debug)
13871433
{
13881434
fprintf(stderr,"%s",buf.data);
13891435
}

‎src/backend/utils/misc/guc.c

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.196 2004/04/05 02:48:09 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.197 2004/04/0503:02:07 momjian Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -75,6 +75,9 @@ extern intCommitSiblings;
7575
externchar*preload_libraries_string;
7676
externintDebugSharedBuffers;
7777

78+
staticconstchar*assign_log_destination(constchar*value,
79+
booldoit,GucSourcesource);
80+
7881
#ifdefHAVE_SYSLOG
7982
externchar*Syslog_facility;
8083
externchar*Syslog_ident;
@@ -143,6 +146,7 @@ static char *client_min_messages_str;
143146
staticchar*log_min_messages_str;
144147
staticchar*log_error_verbosity_str;
145148
staticchar*log_min_error_statement_str;
149+
staticchar*log_destination_string;
146150
staticboolphony_autocommit;
147151
staticboolsession_auth_is_superuser;
148152
staticdoublephony_random_seed;
@@ -279,8 +283,8 @@ const char *const config_group_names[] =
279283
gettext_noop("Query Tuning / Other Planner Options"),
280284
/* LOGGING */
281285
gettext_noop("Reporting and Logging"),
282-
/*LOGGING_SYSLOG */
283-
gettext_noop("Reporting and Logging /Syslog"),
286+
/*LOGGING_WHERE */
287+
gettext_noop("Reporting and Logging /Where to Log"),
284288
/* LOGGING_WHEN */
285289
gettext_noop("Reporting and Logging / When to Log"),
286290
/* LOGGING_WHAT */
@@ -933,20 +937,6 @@ static struct config_int ConfigureNamesInt[] =
933937
1000,0,INT_MAX,NULL,NULL
934938
},
935939

936-
#ifdefHAVE_SYSLOG
937-
{
938-
{"syslog",PGC_SIGHUP,LOGGING_SYSLOG,
939-
gettext_noop("Uses syslog for logging."),
940-
gettext_noop("If this parameter is 1, messages go both to syslog "
941-
"and the standard output. A value of 2 sends output only to syslog. "
942-
"(Some messages will still go to the standard output/error.) The "
943-
"default is 0, which means syslog is off.")
944-
},
945-
&Use_syslog,
946-
0,0,2,NULL,NULL
947-
},
948-
#endif
949-
950940
/*
951941
* Note: There is some postprocessing done in PostmasterMain() to make
952942
* sure the buffers are at least twice the number of backends, so the
@@ -1644,9 +1634,20 @@ static struct config_string ConfigureNamesString[] =
16441634
NULL,assign_session_authorization,show_session_authorization
16451635
},
16461636

1637+
{
1638+
{"log_destination",PGC_POSTMASTER,LOGGING_WHERE,
1639+
gettext_noop("Sets the target for log output."),
1640+
gettext_noop("Valid values are combinations of stderr, syslog "
1641+
"and eventlog, depending on platform."),
1642+
GUC_LIST_INPUT |GUC_REPORT
1643+
},
1644+
&log_destination_string,
1645+
"stderr",assign_log_destination,NULL
1646+
},
1647+
16471648
#ifdefHAVE_SYSLOG
16481649
{
1649-
{"syslog_facility",PGC_POSTMASTER,LOGGING_SYSLOG,
1650+
{"syslog_facility",PGC_POSTMASTER,LOGGING_WHERE,
16501651
gettext_noop("Sets the syslog \"facility\" to be used when syslog enabled."),
16511652
gettext_noop("Valid values are LOCAL0, LOCAL1, LOCAL2, LOCAL3, "
16521653
"LOCAL4, LOCAL5, LOCAL6, LOCAL7.")
@@ -1655,7 +1656,7 @@ static struct config_string ConfigureNamesString[] =
16551656
"LOCAL0",assign_facility,NULL
16561657
},
16571658
{
1658-
{"syslog_ident",PGC_POSTMASTER,LOGGING_SYSLOG,
1659+
{"syslog_ident",PGC_POSTMASTER,LOGGING_WHERE,
16591660
gettext_noop("Sets the program name used to identify PostgreSQL messages "
16601661
"in syslog."),
16611662
NULL
@@ -4418,6 +4419,68 @@ GUCArrayDelete(ArrayType *array, const char *name)
44184419
* assign_hook subroutines
44194420
*/
44204421

4422+
staticconstchar*
4423+
assign_log_destination(constchar*value,booldoit,GucSourcesource)
4424+
{
4425+
char*rawstring;
4426+
List*elemlist;
4427+
List*l;
4428+
unsignedintnewlogdest=0;
4429+
4430+
/* Need a modifiable copy of string */
4431+
rawstring=pstrdup(value);
4432+
4433+
/* Parse string into list of identifiers */
4434+
if (!SplitIdentifierString(rawstring,',',&elemlist))
4435+
{
4436+
/* syntax error in list */
4437+
pfree(rawstring);
4438+
freeList(elemlist);
4439+
if (source >=PGC_S_INTERACTIVE)
4440+
ereport(ERROR,
4441+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4442+
errmsg("invalid list syntax for parameter \"log_destination\"")));
4443+
returnNULL;
4444+
}
4445+
4446+
foreach(l,elemlist)
4447+
{
4448+
char*tok= (char*)lfirst(l);
4449+
4450+
if (strcasecmp(tok,"stderr")==0)
4451+
newlogdest |=LOG_DESTINATION_STDERR;
4452+
#ifdefHAVE_SYSLOG
4453+
elseif (strcasecmp(tok,"syslog")==0)
4454+
newlogdest |=LOG_DESTINATION_SYSLOG;
4455+
#endif
4456+
#ifdefWIN32
4457+
elseif (strcasecmp(tok,"eventlog")==0)
4458+
newlogdest |=LOG_DESTINATION_EVENTLOG;
4459+
#endif
4460+
else {
4461+
if (source >=PGC_S_INTERACTIVE)
4462+
ereport(ERROR,
4463+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4464+
errmsg("unrecognised \"log_destination\" key word: \"%s\"",
4465+
tok)));
4466+
pfree(rawstring);
4467+
freeList(elemlist);
4468+
returnNULL;
4469+
}
4470+
}
4471+
4472+
pfree(rawstring);
4473+
freeList(elemlist);
4474+
4475+
/* If we aren't going to do the assignment, just return OK indicator. */
4476+
if (!doit)
4477+
returnvalue;
4478+
4479+
Log_destination=newlogdest;
4480+
4481+
returnvalue;
4482+
}
4483+
44214484
#ifdefHAVE_SYSLOG
44224485

44234486
staticconstchar*

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@
145145
# ERROR REPORTING AND LOGGING
146146
#---------------------------------------------------------------------------
147147

148-
# -Syslog -
148+
# -Where to Log -
149149

150-
#syslog = 0# range 0-2; 0=stdout; 1=both; 2=syslog
150+
#log_destination = 'stderr'# Valid values are combinations of stderr,
151+
# syslog and eventlog, depending on
152+
# platform.
151153
#syslog_facility = 'LOCAL0'
152154
#syslog_ident = 'postgres'
153155

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp