Add support for logging the current role - Mailing list pgsql-hackers

From Stephen Frost
Subject Add support for logging the current role
Date
Msg-id 20110112142345.GA4933@tamriel.snowman.net
Whole thread Raw
Responses Re: Add support for logging the current role  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Greetings,

Minor enhancement, but a valuable one imv.  Hopefully there aren't any
issues with it. :)
Thanks!
    Stephen

commit 3cb707aa9f228e629e7127625a76a223751a778b
Author: Stephen Frost <sfrost@snowman.net>
Date:   Wed Jan 12 09:17:31 2011 -0500
   Add support for logging the current role      This adds a '%o' option to the log_line_prefix GUC which will log the
current role.  The '%u' option only logs the Session user, which can   be misleading, but it's valuable to have both
options.

*** a/doc/src/sgml/config.sgml
--- b/doc/src/sgml/config.sgml
***************
*** 3508,3513 **** local0.*    /var/log/postgresql
--- 3508,3518 ----              <entry>yes</entry>             </row>             <row>
+              <entry><literal>%o</literal></entry>
+              <entry>Current role name</entry>
+              <entry>yes</entry>
+             </row>
+             <row>              <entry><literal>%d</literal></entry>              <entry>Database name</entry>
    <entry>yes</entry> 
*** a/src/backend/utils/error/elog.c
--- b/src/backend/utils/error/elog.c
***************
*** 1826,1831 **** log_line_prefix(StringInfo buf, ErrorData *edata)
--- 1826,1841 ----                     appendStringInfoString(buf, username);                 }                 break;
+             case 'o':
+                 if (MyProcPort)
+                 {
+                     const char *rolename = GetUserNameFromId(GetUserId());
+
+                     if (rolename == NULL || *rolename == '\0')
+                         rolename = _("[unknown]");
+                     appendStringInfoString(buf, rolename);
+                 }
+                 break;             case 'd':                 if (MyProcPort)                 {

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: ALTER TYPE 1: recheck index-based constraints
Next
From: Alvaro Herrera
Date:
Subject: Re: multiset patch review