[CalendarServer-changes] [14499] CalendarServer/trunk/txdav/base/datastore/subpostgres.py
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 3 16:43:12 PST 2015
Revision: 14499
http://trac.calendarserver.org//changeset/14499
Author: wsanchez at apple.com
Date: 2015-03-03 16:43:11 -0800 (Tue, 03 Mar 2015)
Log Message:
-----------
Make logging from PostgresMonitor cleaner.
Add _connectorFor_pg8000()
Modified Paths:
--------------
CalendarServer/trunk/txdav/base/datastore/subpostgres.py
Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2015-03-04 00:29:34 UTC (rev 14498)
+++ CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2015-03-04 00:43:11 UTC (rev 14499)
@@ -50,10 +50,11 @@
-class _PostgresMonitor(ProcessProtocol):
+class PostgresMonitor(ProcessProtocol):
"""
A monitoring protocol which watches the postgres subprocess.
"""
+ log = Logger()
def __init__(self, svc=None):
self.lineReceiver = LineReceiver()
@@ -79,12 +80,16 @@
def outReceived(self, out):
- log.info("received postgres stdout {out!r}", out=out)
+ for line in out.split("\n"):
+ if line:
+ self.log.info("{message}", message=line)
# self.lineReceiver.dataReceived(out)
def errReceived(self, err):
- log.info("received postgres stderr {err}", err=err)
+ for line in err.split("\n"):
+ if line:
+ self.log.error("{message}", message=line)
self.lineReceiver.dataReceived(err)
@@ -336,9 +341,37 @@
if self.port:
kwargs["host"] = "{}:{}".format(self.host, self.port)
+ log.info(
+ "Connecting to Postgres with dsn={dsn!r} args={args}",
+ dsn=dsn, args=kwargs
+ )
+
return DBAPIConnector(postgres, postgresPreflight, dsn, **kwargs)
+ def _connectorFor_pg8000(self, databaseName):
+ kwargs = dict(database=databaseName)
+
+ if self.host.startswith("/"):
+ kwargs["host"] = None
+ kwargs["unix_sock"] = self.host
+ else:
+ kwargs["host"] = self.host
+ kwargs["unix_sock"] = None
+
+ if self.port:
+ kwargs["port"] = self.port
+
+ if self.spawnedDBUser:
+ kwargs["user"] = self.spawnedDBUser
+ elif self.uid is not None:
+ kwargs["user"] = pwd.getpwuid(self.uid).pw_name
+
+ log.info("Connecting to Postgres with args={args}", args=kwargs)
+
+ return DBAPIConnector(postgres, postgresPreflight, **kwargs)
+
+
def produceConnection(self, label="<unlabeled>", databaseName=None):
"""
Produce a DB-API 2.0 connection pointed at this database.
@@ -438,7 +471,7 @@
createDatabaseCursor.execute("commit")
return createDatabaseConn, createDatabaseCursor
- monitor = _PostgresMonitor(self)
+ monitor = PostgresMonitor(self)
# check consistency of initdb and postgres?
options = []
@@ -638,7 +671,7 @@
# If pg_ctl's startup wasn't successful, don't bother to stop the
# database. (This also happens in command-line tools.)
if self.shouldStopDatabase:
- monitor = _PostgresMonitor()
+ monitor = PostgresMonitor()
# FIXME: why is this 'logfile' and not self.logfile?
self.reactor.spawnProcess(
monitor, self._pgCtl,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150303/35071436/attachment.html>
More information about the calendarserver-changes
mailing list