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

Commitf39df96

Browse files
committed
Add log_line_prefix placeholder %e to contain the current SQL state
Author: Guillaume Smet <guillaume.smet@gmail.com>
1 parente2b42ae commitf39df96

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.220 2009/06/17 21:58:48 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.221 2009/07/03 19:14:25 petere Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -3043,6 +3043,11 @@ local0.* /var/log/postgresql
30433043
<entry>Command tag: type of session's current command</entry>
30443044
<entry>yes</entry>
30453045
</row>
3046+
<row>
3047+
<entry><literal>%e</literal></entry>
3048+
<entry>SQL state</entry>
3049+
<entry>no</entry>
3050+
</row>
30463051
<row>
30473052
<entry><literal>%c</literal></entry>
30483053
<entry>Session ID: see below</entry>

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

Lines changed: 15 additions & 12 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.216 2009/06/25 23:07:15 tgl Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.217 2009/07/03 19:14:25 petere Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -144,7 +144,7 @@ static char formatted_log_time[FORMATTED_TS_LEN];
144144
} while (0)
145145

146146

147-
staticvoidlog_line_prefix(StringInfobuf);
147+
staticvoidlog_line_prefix(StringInfobuf,ErrorData*edata);
148148
staticvoidsend_message_to_server_log(ErrorData*edata);
149149
staticvoidsend_message_to_frontend(ErrorData*edata);
150150
staticchar*expand_fmt_string(constchar*fmt,ErrorData*edata);
@@ -1677,7 +1677,7 @@ setup_formatted_start_time(void)
16771677
* Format tag info for log lines; append to the provided buffer.
16781678
*/
16791679
staticvoid
1680-
log_line_prefix(StringInfobuf)
1680+
log_line_prefix(StringInfobuf,ErrorData*edata)
16811681
{
16821682
/* static counter for line numbers */
16831683
staticlonglog_line_number=0;
@@ -1814,6 +1814,9 @@ log_line_prefix(StringInfo buf)
18141814
case'x':
18151815
appendStringInfo(buf,"%u",GetTopTransactionIdIfAny());
18161816
break;
1817+
case'e':
1818+
appendStringInfoString(buf,unpack_sql_state(edata->sqlerrcode));
1819+
break;
18171820
case'%':
18181821
appendStringInfoChar(buf,'%');
18191822
break;
@@ -2070,7 +2073,7 @@ send_message_to_server_log(ErrorData *edata)
20702073

20712074
formatted_log_time[0]='\0';
20722075

2073-
log_line_prefix(&buf);
2076+
log_line_prefix(&buf,edata);
20742077
appendStringInfo(&buf,"%s: ",error_severity(edata->elevel));
20752078

20762079
if (Log_error_verbosity >=PGERROR_VERBOSE)
@@ -2094,35 +2097,35 @@ send_message_to_server_log(ErrorData *edata)
20942097
{
20952098
if (edata->detail_log)
20962099
{
2097-
log_line_prefix(&buf);
2100+
log_line_prefix(&buf,edata);
20982101
appendStringInfoString(&buf,_("DETAIL: "));
20992102
append_with_tabs(&buf,edata->detail_log);
21002103
appendStringInfoChar(&buf,'\n');
21012104
}
21022105
elseif (edata->detail)
21032106
{
2104-
log_line_prefix(&buf);
2107+
log_line_prefix(&buf,edata);
21052108
appendStringInfoString(&buf,_("DETAIL: "));
21062109
append_with_tabs(&buf,edata->detail);
21072110
appendStringInfoChar(&buf,'\n');
21082111
}
21092112
if (edata->hint)
21102113
{
2111-
log_line_prefix(&buf);
2114+
log_line_prefix(&buf,edata);
21122115
appendStringInfoString(&buf,_("HINT: "));
21132116
append_with_tabs(&buf,edata->hint);
21142117
appendStringInfoChar(&buf,'\n');
21152118
}
21162119
if (edata->internalquery)
21172120
{
2118-
log_line_prefix(&buf);
2121+
log_line_prefix(&buf,edata);
21192122
appendStringInfoString(&buf,_("QUERY: "));
21202123
append_with_tabs(&buf,edata->internalquery);
21212124
appendStringInfoChar(&buf,'\n');
21222125
}
21232126
if (edata->context)
21242127
{
2125-
log_line_prefix(&buf);
2128+
log_line_prefix(&buf,edata);
21262129
appendStringInfoString(&buf,_("CONTEXT: "));
21272130
append_with_tabs(&buf,edata->context);
21282131
appendStringInfoChar(&buf,'\n');
@@ -2132,14 +2135,14 @@ send_message_to_server_log(ErrorData *edata)
21322135
/* assume no newlines in funcname or filename... */
21332136
if (edata->funcname&&edata->filename)
21342137
{
2135-
log_line_prefix(&buf);
2138+
log_line_prefix(&buf,edata);
21362139
appendStringInfo(&buf,_("LOCATION: %s, %s:%d\n"),
21372140
edata->funcname,edata->filename,
21382141
edata->lineno);
21392142
}
21402143
elseif (edata->filename)
21412144
{
2142-
log_line_prefix(&buf);
2145+
log_line_prefix(&buf,edata);
21432146
appendStringInfo(&buf,_("LOCATION: %s:%d\n"),
21442147
edata->filename,edata->lineno);
21452148
}
@@ -2153,7 +2156,7 @@ send_message_to_server_log(ErrorData *edata)
21532156
debug_query_string!=NULL&&
21542157
!edata->hide_stmt)
21552158
{
2156-
log_line_prefix(&buf);
2159+
log_line_prefix(&buf,edata);
21572160
appendStringInfoString(&buf,_("STATEMENT: "));
21582161
append_with_tabs(&buf,debug_query_string);
21592162
appendStringInfoChar(&buf,'\n');

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
# %t = timestamp without milliseconds
338338
# %m = timestamp with milliseconds
339339
# %i = command tag
340+
# %e = SQL state
340341
# %c = session ID
341342
# %l = session line number
342343
# %s = session start timestamp

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp