dabo Commit
Revision 4823
Date: 2008-12-11 14:42:35 -0800 (Thu, 11 Dec 2008)
Author: Cito
Trac: http://trac.dabodev.com/dabo/changeset/4823
Changed:
U trunk/dabo/dException.py
U trunk/dabo/lib/logger.py
Log:
Fixed logging problems with PostgreSQL (ticket #1187).
Diff:
Modified: trunk/dabo/dException.py
===================================================================
--- trunk/dabo/dException.py 2008-12-11 22:28:44 UTC (rev 4822)
+++ trunk/dabo/dException.py 2008-12-11 22:42:35 UTC (rev 4823)
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
class dException(StandardError):
""" Base class in the framework for passing exceptions."""
-
+
class FontException(dException):
pass
@@ -27,10 +27,10 @@
class BusinessRuleViolation(dException):
pass
-
+
class BusinessRulePassed(dException):
pass
-
+
class RowNotFoundException(dException):
pass
@@ -40,8 +40,8 @@
class StopIterationException(dException):
pass
-
+
class FeatureNotSupportedException(dException):
pass
@@ -63,7 +63,7 @@
class DBNoAccessException(DatabaseException):
pass
-
+
class DBNoDBOnHostException(DatabaseException):
pass
@@ -72,13 +72,14 @@
class DBQueryException(DatabaseException):
def __init__(self, err, sql=None):
- if sql is None:
- sql = ""
- self.sql = sql
- self.err_desc = "%s" % err
-
+ self.err_desc = unicode(str(err), 'utf-8').rstrip()
+ self.sql = sql and sql.strip() or None
+
def __str__(self):
- return self.err_desc + '\nSQL: ' + self.sql
+ err = self.err_desc
+ if self.sql:
+ err += '\nSQL: ' + self.sql
+ return err
class XmlException(dException):
pass
Modified: trunk/dabo/lib/logger.py
===================================================================
--- trunk/dabo/lib/logger.py 2008-12-11 22:28:44 UTC (rev 4822)
+++ trunk/dabo/lib/logger.py 2008-12-11 22:42:35 UTC (rev 4823)
@@ -4,88 +4,90 @@
from dabo.dLocalize import _
class Log(dObject):
- """ Generic logger object for Dabo.
-
+ """ Generic logger object for Dabo.
+
The main dabo module will instantiate singleton instances of this, which
custom code can override to redirect the writing of informational and
error
messages.
-
+
So, to display general informational messages, call:
dabo.infoLog.write("message")
-
+
For error messages, call:
dabo.errorLog.write("message")
-
+
By default, infoLog writes to stdout and errorLog to stderr. But your
code
can redirect these messages however you please. Just set the LogObject
property
- to an instance that has a write() method that will receive and act on
the
+ to an instance that has a write() method that will receive and act on
the
message. For example, you can redirect to a file:
-
+
dabo.errorLog.LogObject = open("/tmp/error.log", "w")
dabo.infoLog.LogObject = open("/dev/null", "w")
-
+
You can set the logs to arbitrary objects. As long as the object has a
write()
method that receives a message parameter, it will work.
"""
-
+
def write(self, message):
"""Writes the passed message to the log."""
if self.LogObject is None:
# Send messages to the bit bucket...
return
+ msg = []
+ if self.Caption:
+ msg.append("%s: " % self.Caption)
if self.LogTimeStamp:
- timestamp = "%s: " % time.asctime()
- else:
- timestamp = ""
- if len(self.Caption) > 0:
- caption = "%s: " % self.Caption
- else:
- caption = ""
- self.LogObject.write("%s%s%s%s" % (caption, timestamp, message,
os.linesep))
+ msg.append("%s: " % time.asctime())
+ msg.append(message)
+ msg.append(os.linesep)
+ msg = ''.join(msg)
+ try:
+ self.LogObject.write(msg)
+ except UnicodeEncodeError:
+ self.LogObject.write(msg.encode('utf-8'))
# Flush the log entry to the file
try:
self.LogObject.flush()
except (AttributeError, IOError):
pass
-
-
+
+
def _getCaption(self):
try:
return self._caption
except AttributeError:
return ""
-
+
def _setCaption(self, val):
self._caption = str(val)
-
-
+
+
def _getLogObject(self):
try:
return self._logObject
except AttributeError:
return sys.stdout
-
+
def _setLogObject(self, logObject):
# assume that logObject is an object with a write() method...
self._logObject = logObject
-
-
+
+
def _getLogTimeStamp(self):
try:
return self._logTimeStamp
except AttributeError:
return True
-
+
def _setLogTimeStamp(self, val):
self._logTimeStamp = bool(val)
-
+
Caption = property(_getCaption, _setCaption, None,
_("The log's label: will get prepended to the log entry"))
-
- LogObject = property(_getLogObject, _setLogObject, None,
+
+ LogObject = property(_getLogObject, _setLogObject, None,
_("The object that is to receive the log messages."))
-
+
LogTimeStamp = property(_getLogTimeStamp, _setLogTimeStamp, None,
_("Specifies whether a timestamp is logged with the message.
Default: True"))
-
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]