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

Commit3e00496

Browse files
committed
Refactor some duplicate code to set up formatted_log_time and
formatted_start_time.
1 parente4fb8ff commit3e00496

File tree

1 file changed

+62
-72
lines changed

1 file changed

+62
-72
lines changed

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

Lines changed: 62 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.207 2008/10/09 17:24:05 alvherre Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.208 2008/10/17 22:56:16 alvherre Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -146,6 +146,8 @@ static void append_with_tabs(StringInfo buf, const char *str);
146146
staticboolis_log_level_output(intelevel,intlog_min_level);
147147
staticvoidwrite_pipe_chunks(char*data,intlen,intdest);
148148
staticvoidwrite_csvlog(ErrorData*edata);
149+
staticvoidsetup_formatted_log_time(void);
150+
staticvoidsetup_formatted_start_time(void);
149151

150152
/*
151153
* errstart --- begin an error-reporting cycle
@@ -1481,6 +1483,60 @@ write_eventlog(int level, const char *line)
14811483
}
14821484
#endif/* WIN32 */
14831485

1486+
/*
1487+
* setup formatted_log_time, for consistent times between CSV and regular logs
1488+
*/
1489+
staticvoid
1490+
setup_formatted_log_time(void)
1491+
{
1492+
structtimevaltv;
1493+
pg_time_tstamp_time;
1494+
pg_tz*tz;
1495+
charmsbuf[8];
1496+
1497+
gettimeofday(&tv,NULL);
1498+
stamp_time= (pg_time_t)tv.tv_sec;
1499+
1500+
/*
1501+
* Normally we print log timestamps in log_timezone, but during startup we
1502+
* could get here before that's set. If so, fall back to gmt_timezone
1503+
* (which guc.c ensures is set up before Log_line_prefix can become
1504+
* nonempty).
1505+
*/
1506+
tz=log_timezone ?log_timezone :gmt_timezone;
1507+
1508+
pg_strftime(formatted_log_time,FORMATTED_TS_LEN,
1509+
/* leave room for milliseconds... */
1510+
"%Y-%m-%d %H:%M:%S %Z",
1511+
pg_localtime(&stamp_time,tz));
1512+
1513+
/* 'paste' milliseconds into place... */
1514+
sprintf(msbuf,".%03d", (int) (tv.tv_usec /1000));
1515+
strncpy(formatted_log_time+19,msbuf,4);
1516+
}
1517+
1518+
/*
1519+
* setup formatted_start_time
1520+
*/
1521+
staticvoid
1522+
setup_formatted_start_time(void)
1523+
{
1524+
pg_time_tstamp_time= (pg_time_t)MyStartTime;
1525+
pg_tz*tz;
1526+
1527+
/*
1528+
* Normally we print log timestamps in log_timezone, but during startup we
1529+
* could get here before that's set. If so, fall back to gmt_timezone
1530+
* (which guc.c ensures is set up before Log_line_prefix can become
1531+
* nonempty).
1532+
*/
1533+
tz=log_timezone ?log_timezone :gmt_timezone;
1534+
1535+
pg_strftime(formatted_start_time,FORMATTED_TS_LEN,
1536+
"%Y-%m-%d %H:%M:%S %Z",
1537+
pg_localtime(&stamp_time,tz));
1538+
}
1539+
14841540
/*
14851541
* Format tag info for log lines; append to the provided buffer.
14861542
*/
@@ -1561,34 +1617,8 @@ log_line_prefix(StringInfo buf)
15611617
appendStringInfo(buf,"%ld",log_line_number);
15621618
break;
15631619
case'm':
1564-
{
1565-
structtimevaltv;
1566-
pg_time_tstamp_time;
1567-
pg_tz*tz;
1568-
charmsbuf[8];
1569-
1570-
gettimeofday(&tv,NULL);
1571-
stamp_time= (pg_time_t)tv.tv_sec;
1572-
1573-
/*
1574-
* Normally we print log timestamps in log_timezone, but
1575-
* during startup we could get here before that's set. If
1576-
* so, fall back to gmt_timezone (which guc.c ensures is
1577-
* set up before Log_line_prefix can become nonempty).
1578-
*/
1579-
tz=log_timezone ?log_timezone :gmt_timezone;
1580-
1581-
pg_strftime(formatted_log_time,FORMATTED_TS_LEN,
1582-
/* leave room for milliseconds... */
1583-
"%Y-%m-%d %H:%M:%S %Z",
1584-
pg_localtime(&stamp_time,tz));
1585-
1586-
/* 'paste' milliseconds into place... */
1587-
sprintf(msbuf,".%03d", (int) (tv.tv_usec /1000));
1588-
strncpy(formatted_log_time+19,msbuf,4);
1589-
1590-
appendStringInfoString(buf,formatted_log_time);
1591-
}
1620+
setup_formatted_log_time();
1621+
appendStringInfoString(buf,formatted_log_time);
15921622
break;
15931623
case't':
15941624
{
@@ -1606,16 +1636,7 @@ log_line_prefix(StringInfo buf)
16061636
break;
16071637
case's':
16081638
if (formatted_start_time[0]=='\0')
1609-
{
1610-
pg_time_tstamp_time= (pg_time_t)MyStartTime;
1611-
pg_tz*tz;
1612-
1613-
tz=log_timezone ?log_timezone :gmt_timezone;
1614-
1615-
pg_strftime(formatted_start_time,FORMATTED_TS_LEN,
1616-
"%Y-%m-%d %H:%M:%S %Z",
1617-
pg_localtime(&stamp_time,tz));
1618-
}
1639+
setup_formatted_start_time();
16191640
appendStringInfoString(buf,formatted_start_time);
16201641
break;
16211642
case'i':
@@ -1731,32 +1752,8 @@ write_csvlog(ErrorData *edata)
17311752
* to put same timestamp in both syslog and csvlog messages.
17321753
*/
17331754
if (formatted_log_time[0]=='\0')
1734-
{
1735-
structtimevaltv;
1736-
pg_time_tstamp_time;
1737-
pg_tz*tz;
1738-
charmsbuf[8];
1739-
1740-
gettimeofday(&tv,NULL);
1741-
stamp_time= (pg_time_t)tv.tv_sec;
1742-
1743-
/*
1744-
* Normally we print log timestamps in log_timezone, but during
1745-
* startup we could get here before that's set. If so, fall back to
1746-
* gmt_timezone (which guc.c ensures is set up before Log_line_prefix
1747-
* can become nonempty).
1748-
*/
1749-
tz=log_timezone ?log_timezone :gmt_timezone;
1750-
1751-
pg_strftime(formatted_log_time,FORMATTED_TS_LEN,
1752-
/* leave room for milliseconds... */
1753-
"%Y-%m-%d %H:%M:%S %Z",
1754-
pg_localtime(&stamp_time,tz));
1755+
setup_formatted_log_time();
17551756

1756-
/* 'paste' milliseconds into place... */
1757-
sprintf(msbuf,".%03d", (int) (tv.tv_usec /1000));
1758-
strncpy(formatted_log_time+19,msbuf,4);
1759-
}
17601757
appendStringInfoString(&buf,formatted_log_time);
17611758
appendStringInfoChar(&buf,',');
17621759

@@ -1813,14 +1810,7 @@ write_csvlog(ErrorData *edata)
18131810

18141811
/* session start timestamp */
18151812
if (formatted_start_time[0]=='\0')
1816-
{
1817-
pg_time_tstamp_time= (pg_time_t)MyStartTime;
1818-
pg_tz*tz=log_timezone ?log_timezone :gmt_timezone;
1819-
1820-
pg_strftime(formatted_start_time,FORMATTED_TS_LEN,
1821-
"%Y-%m-%d %H:%M:%S %Z",
1822-
pg_localtime(&stamp_time,tz));
1823-
}
1813+
setup_formatted_start_time();
18241814
appendStringInfoString(&buf,formatted_start_time);
18251815
appendStringInfoChar(&buf,',');
18261816

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp