mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Removed ELOG_TIMESTAMPS #define in favor of two run-time
configuration options `Log_timestamp' and `Log_pid'.
This commit is contained in:
parent
209aa77d98
commit
0a54de8faf
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.59 2000/05/31 00:28:32 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.60 2000/06/04 15:06:29 petere Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -57,15 +57,14 @@ static void write_syslog(int level, const char *line);
|
|||||||
# define Use_syslog 0
|
# define Use_syslog 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool Log_timestamp;
|
||||||
|
bool Log_pid;
|
||||||
|
|
||||||
|
#define TIMESTAMP_SIZE 20 /* format `YYYY-MM-DD HH:MM:SS ' */
|
||||||
|
#define PID_SIZE 9 /* format `[123456] ' */
|
||||||
|
|
||||||
#ifdef ELOG_TIMESTAMPS
|
|
||||||
static const char * print_timestamp(void);
|
static const char * print_timestamp(void);
|
||||||
# define TIMESTAMP_SIZE 28
|
static const char * print_pid(void);
|
||||||
#else
|
|
||||||
# define TIMESTAMP_SIZE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int Debugfile = -1;
|
static int Debugfile = -1;
|
||||||
static int Err_file = -1;
|
static int Err_file = -1;
|
||||||
@ -117,11 +116,9 @@ elog(int lev, const char *fmt,...)
|
|||||||
int indent = 0;
|
int indent = 0;
|
||||||
int space_needed;
|
int space_needed;
|
||||||
|
|
||||||
#ifdef USE_SYSLOG
|
|
||||||
int log_level;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
int len;
|
int len;
|
||||||
|
/* size of the prefix needed for timestamp and pid, if enabled */
|
||||||
|
size_t timestamp_size;
|
||||||
|
|
||||||
if (lev <= DEBUG && Debugfile < 0)
|
if (lev <= DEBUG && Debugfile < 0)
|
||||||
return; /* ignore debug msgs if noplace to send */
|
return; /* ignore debug msgs if noplace to send */
|
||||||
@ -174,13 +171,19 @@ elog(int lev, const char *fmt,...)
|
|||||||
errorstr = errorstr_buf;
|
errorstr = errorstr_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timestamp_size = 0;
|
||||||
|
if (Log_timestamp)
|
||||||
|
timestamp_size += TIMESTAMP_SIZE;
|
||||||
|
if (Log_pid)
|
||||||
|
timestamp_size += PID_SIZE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the expanded format, consisting of the prefix string plus
|
* Set up the expanded format, consisting of the prefix string plus
|
||||||
* input format, with any %m replaced by strerror() string (since
|
* input format, with any %m replaced by strerror() string (since
|
||||||
* vsnprintf won't know what to do with %m). To keep space
|
* vsnprintf won't know what to do with %m). To keep space
|
||||||
* calculation simple, we only allow one %m.
|
* calculation simple, we only allow one %m.
|
||||||
*/
|
*/
|
||||||
space_needed = TIMESTAMP_SIZE + strlen(prefix) + indent + (lineno ? 24 : 0)
|
space_needed = timestamp_size + strlen(prefix) + indent + (lineno ? 24 : 0)
|
||||||
+ strlen(fmt) + strlen(errorstr) + 1;
|
+ strlen(fmt) + strlen(errorstr) + 1;
|
||||||
if (space_needed > (int) sizeof(fmt_fixedbuf))
|
if (space_needed > (int) sizeof(fmt_fixedbuf))
|
||||||
{
|
{
|
||||||
@ -194,12 +197,16 @@ elog(int lev, const char *fmt,...)
|
|||||||
* fmt_fixedbuf! */
|
* fmt_fixedbuf! */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef ELOG_TIMESTAMPS
|
|
||||||
strcpy(fmt_buf, print_timestamp());
|
fmt_buf[0] = '\0';
|
||||||
|
|
||||||
|
if (Log_timestamp)
|
||||||
|
strcat(fmt_buf, print_timestamp());
|
||||||
|
if (Log_pid)
|
||||||
|
strcat(fmt_buf, print_pid());
|
||||||
|
|
||||||
strcat(fmt_buf, prefix);
|
strcat(fmt_buf, prefix);
|
||||||
#else
|
|
||||||
strcpy(fmt_buf, prefix);
|
|
||||||
#endif
|
|
||||||
bp = fmt_buf + strlen(fmt_buf);
|
bp = fmt_buf + strlen(fmt_buf);
|
||||||
while (indent-- > 0)
|
while (indent-- > 0)
|
||||||
*bp++ = ' ';
|
*bp++ = ' ';
|
||||||
@ -277,12 +284,12 @@ elog(int lev, const char *fmt,...)
|
|||||||
/* We're up against it, convert to fatal out-of-memory error */
|
/* We're up against it, convert to fatal out-of-memory error */
|
||||||
msg_buf = msg_fixedbuf;
|
msg_buf = msg_fixedbuf;
|
||||||
lev = REALLYFATAL;
|
lev = REALLYFATAL;
|
||||||
#ifdef ELOG_TIMESTAMPS
|
msg_buf[0] = '\0';
|
||||||
strcpy(msg_buf, print_timestamp());
|
if (Log_timestamp)
|
||||||
|
strcat(msg_buf, print_timestamp());
|
||||||
|
if (Log_pid)
|
||||||
|
strcat(msg_buf, print_pid());
|
||||||
strcat(msg_buf, "FATAL: elog: out of memory");
|
strcat(msg_buf, "FATAL: elog: out of memory");
|
||||||
#else
|
|
||||||
strcpy(msg_buf, "FATAL: elog: out of memory");
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,7 +325,7 @@ elog(int lev, const char *fmt,...)
|
|||||||
syslog_level = LOG_CRIT;
|
syslog_level = LOG_CRIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_syslog(syslog_level, msg_buf + TIMESTAMP_SIZE);
|
write_syslog(syslog_level, msg_buf + timestamp_size);
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_SYSLOG */
|
#endif /* ENABLE_SYSLOG */
|
||||||
|
|
||||||
@ -373,7 +380,7 @@ elog(int lev, const char *fmt,...)
|
|||||||
msgtype = 'E';
|
msgtype = 'E';
|
||||||
}
|
}
|
||||||
/* exclude the timestamp from msg sent to frontend */
|
/* exclude the timestamp from msg sent to frontend */
|
||||||
pq_puttextmessage(msgtype, msg_buf + TIMESTAMP_SIZE);
|
pq_puttextmessage(msgtype, msg_buf + timestamp_size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This flush is normally not necessary, since postgres.c will
|
* This flush is normally not necessary, since postgres.c will
|
||||||
@ -525,33 +532,45 @@ DebugFileOpen(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef ELOG_TIMESTAMPS
|
|
||||||
/*
|
/*
|
||||||
* Return a timestamp string like "980119.17:25:59.902 [21974] "
|
* Return a timestamp string like
|
||||||
|
*
|
||||||
|
* "2000-06-04 13:12:03 "
|
||||||
*/
|
*/
|
||||||
static const char *
|
static const char *
|
||||||
print_timestamp()
|
print_timestamp(void)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
time_t curtime;
|
||||||
struct timezone tz = { 0, 0 };
|
static char buf[TIMESTAMP_SIZE + 1];
|
||||||
struct tm *time;
|
|
||||||
time_t tm;
|
|
||||||
static char timestamp[32],
|
|
||||||
pid[8];
|
|
||||||
|
|
||||||
gettimeofday(&tv, &tz);
|
curtime = time(NULL);
|
||||||
tm = tv.tv_sec;
|
|
||||||
time = localtime(&tm);
|
|
||||||
|
|
||||||
sprintf(pid, "[%d]", MyProcPid);
|
strftime(buf, sizeof(buf),
|
||||||
sprintf(timestamp, "%02d%02d%02d.%02d:%02d:%02d.%03d %7s ",
|
"%Y-%m-%d %H:%M:%S ",
|
||||||
time->tm_year % 100, time->tm_mon + 1, time->tm_mday,
|
localtime(&curtime));
|
||||||
time->tm_hour, time->tm_min, time->tm_sec,
|
|
||||||
(int) (tv.tv_usec/1000), pid);
|
|
||||||
|
|
||||||
return timestamp;
|
return buf;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a string like
|
||||||
|
*
|
||||||
|
* "[123456] "
|
||||||
|
*
|
||||||
|
* with the current pid.
|
||||||
|
*/
|
||||||
|
static const char *
|
||||||
|
print_pid(void)
|
||||||
|
{
|
||||||
|
static char buf[PID_SIZE + 1];
|
||||||
|
|
||||||
|
snprintf(buf, PID_SIZE + 1, "[%d] ", (int)MyProcPid);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_SYSLOG
|
#ifdef ENABLE_SYSLOG
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* Support for grand unified configuration scheme, including SET
|
* Support for grand unified configuration scheme, including SET
|
||||||
* command, configuration file, and command line options.
|
* command, configuration file, and command line options.
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.1 2000/05/31 00:28:34 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.2 2000/06/04 15:06:30 petere Exp $
|
||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* Copyright 2000 by PostgreSQL Global Development Group
|
||||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||||
@ -139,9 +139,11 @@ ConfigureNamesBool[] =
|
|||||||
{"geqo", PGC_USERSET, &enable_geqo, true},
|
{"geqo", PGC_USERSET, &enable_geqo, true},
|
||||||
|
|
||||||
{"net_server", PGC_POSTMASTER, &NetServer, false},
|
{"net_server", PGC_POSTMASTER, &NetServer, false},
|
||||||
{"fsync", PGC_POSTMASTER, &enableFsync, true},
|
{"fsync", PGC_BACKEND, &enableFsync, true},
|
||||||
|
|
||||||
{"log_connections", PGC_POSTMASTER, &Log_connections, false},
|
{"log_connections", PGC_POSTMASTER, &Log_connections, false},
|
||||||
|
{"log_timestamp", PGC_BACKEND, &Log_timestamp, false},
|
||||||
|
{"log_pid", PGC_BACKEND, &Log_pid, false},
|
||||||
|
|
||||||
{"debug_print_query", PGC_SUSET, &Debug_print_query, false},
|
{"debug_print_query", PGC_SUSET, &Debug_print_query, false},
|
||||||
{"debug_print_parse", PGC_SUSET, &Debug_print_parse, false},
|
{"debug_print_parse", PGC_SUSET, &Debug_print_parse, false},
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* or in config.h afterwards. Of course, if you edit config.h, then your
|
* or in config.h afterwards. Of course, if you edit config.h, then your
|
||||||
* changes will be overwritten the next time you run configure.
|
* changes will be overwritten the next time you run configure.
|
||||||
*
|
*
|
||||||
* $Id: config.h.in,v 1.115 2000/06/04 01:44:36 petere Exp $
|
* $Id: config.h.in,v 1.116 2000/06/04 15:06:32 petere Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
@ -140,11 +140,6 @@
|
|||||||
*/
|
*/
|
||||||
#define TBL_FREE_CMD_MEMORY
|
#define TBL_FREE_CMD_MEMORY
|
||||||
|
|
||||||
/*
|
|
||||||
* ELOG_TIMESTAMPS: adds a timestamp with the following format to elog
|
|
||||||
* messages: yymmdd.hh:mm:ss.mmm [pid] message
|
|
||||||
*/
|
|
||||||
/* #define ELOG_TIMESTAMPS */
|
|
||||||
|
|
||||||
#undef ENABLE_SYSLOG
|
#undef ENABLE_SYSLOG
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: elog.h,v 1.17 2000/05/31 00:28:40 petere Exp $
|
* $Id: elog.h,v 1.18 2000/06/04 15:06:34 petere Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -27,6 +27,9 @@
|
|||||||
extern int Use_syslog;
|
extern int Use_syslog;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern bool Log_timestamp;
|
||||||
|
extern bool Log_pid;
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
extern void elog(int lev, const char *fmt,...);
|
extern void elog(int lev, const char *fmt,...);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user