dabo Commit
Revision 5958
Date: 2010-08-22 13:17:38 -0700 (Sun, 22 Aug 2010)
Author: Ed
Trac: http://trac.dabodev.com/changeset/5958
Changed:
U trunk/dabo/__init__.py
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/dApp.py
U trunk/dabo/dEvents.py
U trunk/dabo/dLocalize.py
U trunk/dabo/dObject.py
U trunk/dabo/dPref.py
U trunk/dabo/db/dBackend.py
U trunk/dabo/db/dConnectInfo.py
U trunk/dabo/db/dCursorMixin.py
U trunk/dabo/db/dDataSet.py
U trunk/dabo/db/dbFirebird.py
U trunk/dabo/db/dbMySQL.py
U trunk/dabo/db/dbOracle.py
U trunk/dabo/db/dbPostgreSQL.py
U trunk/dabo/db/dbSQLite.py
U trunk/dabo/lib/RemoteConnector.py
U trunk/dabo/lib/datanav/Page.py
U trunk/dabo/lib/logger.py
A trunk/dabo/logging.conf
U trunk/dabo/settings.py
U trunk/dabo/ui/__init__.py
U trunk/dabo/ui/dDataControlMixinBase.py
U trunk/dabo/ui/uitk/__init__.py
U trunk/dabo/ui/uitk/dFormMixin.py
U trunk/dabo/ui/uitk/dPemMixin.py
U trunk/dabo/ui/uitk/uiApp.py
U trunk/dabo/ui/uiwx/__init__.py
U trunk/dabo/ui/uiwx/dDataControlMixin.py
U trunk/dabo/ui/uiwx/dDateTextBox.py
U trunk/dabo/ui/uiwx/dDockForm.py
U trunk/dabo/ui/uiwx/dEditor.py
U trunk/dabo/ui/uiwx/dFont.py
U trunk/dabo/ui/uiwx/dForm.py
U trunk/dabo/ui/uiwx/dFormMixin.py
U trunk/dabo/ui/uiwx/dGlWindow.py
U trunk/dabo/ui/uiwx/dGrid.py
U trunk/dabo/ui/uiwx/dGridSizer.py
U trunk/dabo/ui/uiwx/dImage.py
U trunk/dabo/ui/uiwx/dLinePlot.py
U trunk/dabo/ui/uiwx/dListControl.py
U trunk/dabo/ui/uiwx/dMaskedTextBox.py
U trunk/dabo/ui/uiwx/dPageFrame.py
U trunk/dabo/ui/uiwx/dPemMixin.py
U trunk/dabo/ui/uiwx/dRadioList.py
U trunk/dabo/ui/uiwx/dRichTextBox.py
U trunk/dabo/ui/uiwx/dSizerMixin.py
U trunk/dabo/ui/uiwx/dSlidePanelControl.py
U trunk/dabo/ui/uiwx/dSlider.py
U trunk/dabo/ui/uiwx/dSpinner.py
U trunk/dabo/ui/uiwx/dTextBoxMixin.py
U trunk/dabo/ui/uiwx/uiApp.py
Log:
Switched all of Dabo's logging to standard Python logging. Now instead of
calling:
dabo.infoLog.write("some message")
dabo.errorLog.write("some message")
...the calls will be:
dabo.log.info("some message")
dabo.log.error("some message")
I've also merged the dbActivityLog into the same common logging. It is no
longer activated by the 'DatabaseActivityLog' in dApp; instead, you must change
the configuration before the app is run to include an actual file name to write
to instead of the default of os.devnull.
I've converted all the old calls to the new style. There should be a lot of
testing and a lot of feedback to improve this first step.
Diff:
Modified: trunk/dabo/__init__.py
===================================================================
--- trunk/dabo/__init__.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/__init__.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -101,6 +101,7 @@
import os
import locale
import logging
+import logging.handlers
try:
import pysqlite2
except ImportError:
@@ -126,30 +127,59 @@
# we want to make them part of the dabo namespace.
from settings import *
-# Instantiate the logger object, which will send messages to user-overridable
-# locations. Do this before any other imports.
-from dabo.lib.logger import Log
-infoLog = Log()
-infoLog.Caption = "Dabo Info Log"
-if verboseLogging:
- infoLog.LogObject = sys.stdout
-else:
- class NullWrite(object):
- def write(self, txt): pass
- infoLog.LogObject = NullWrite()
-errorLog = Log()
-errorLog.Caption = "Dabo Error Log"
-errorLog.LogObject = sys.stderr
-# Create a separate log reference for event tracking.
-eventLog = Log()
-eventLog.Caption = "Dabo Event Log"
-eventLog.LogObject = sys.stdout
-# This log is set to None by default. It must be manually activated
-# via the Application object.
-dbActivityLog = Log()
-dbActivityLog.Caption = "Database Activity Log"
-dbActivityLog.LogObject = None
+_logConfFileName = "logging.conf"
+logConfFile = os.path.join(os.getcwd(), _logConfFileName)
+if not os.path.exists(logConfFile):
+ daboloc = os.path.dirname(__file__)
+ logConfFile = os.path.join(daboloc, _logConfFileName)
+import logging.config
+logging.config.fileConfig(logConfFile)
+log = logging.getLogger("dabo.mainLog")
+dbActivityLog = logging.getLogger("dabo.dbActivityLog")
+consoleLog = fileLog = dbLog = None
+for _handler in log.handlers:
+ try:
+ _handler.baseFilename
+ fileLog = _handler
+ except AttributeError:
+ consoleLog = _handler
+for _handler in dbActivityLog.handlers:
+ try:
+ _handler.baseFilename
+ dbLog = _handler
+ break
+ except AttributeError:
+ pass
+
+
+########################################################
+#### The commented out code was a first attempt at using Python logging, but
with
+#### the dabo.settings file being used to configure instead of logging.conf
+########################################################
+# logConsoleHandler = logging.StreamHandler()
+# logConsoleHandler.setLevel(logConsoleLevel)
+# logFileHandler = logging.handlers.RotatingFileHandler(filename=logFile,
maxBytes=maxLogFileSize,
+# encoding=defaultEncoding)
+# logFileHandler.setLevel(logFileLevel)
+# consoleFormatter = logging.Formatter(consoleFormat)
+# fileFormatter = logging.Formatter(fileFormat)
+# logConsoleHandler.setFormatter(consoleFormatter)
+# logFileHandler.setFormatter(fileFormatter)
+# log = logging.getLogger(logName)
+# log.setLevel(logging.DEBUG)
+# log.addHandler(logConsoleHandler)
+# log.addHandler(logFileHandler)
+#
+# This log is set to the null output device ('nul' on Windows; /dev/null on
the rest)
+# dbActivityLog = logging.getLogger("dabo.dbActivityLog")
+# dbLogHandler = logging.handlers.RotatingFileHandler(filename=dbLogFile,
maxBytes=maxLogFileSize,
+# encoding=defaultEncoding)
+# dbActivityLog.addHandler(dbLogHandler)
+# dbActivityLog.setLevel(dbLogFileLevel)
+# dbLogHandler.setLevel(dbLogFileLevel)
+########################################################
+
# Install localization service for dabo. dApp will install localization service
# for the user application separately.
import dLocalize
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/biz/dBizobj.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -427,7 +427,7 @@
self.RowNumber = current_row
except StandardError, e:
# Need to record what sort of error could be
thrown
- dabo.errorLog.write(_("Failed to set RowNumber.
Error: %s") % e)
+ dabo.log.error(_("Failed to set RowNumber.
Error: %s") % e)
def save(self, startTransaction=True):
@@ -831,7 +831,7 @@
func(*args, **kwargs)
except StandardError, e:
# Reset things and bail
- dabo.errorLog.write(_("Error in
scanChangedRows: %s") % e)
+ dabo.log.error(_("Error in
scanChangedRows: %s") % e)
self._CurrentCursor =
old_currentCursorKey
self._positionUsingPK(old_pk)
raise
Modified: trunk/dabo/dApp.py
===================================================================
--- trunk/dabo/dApp.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/dApp.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -293,7 +293,7 @@
rp.syncFiles()
except urllib2.URLError, e:
# Cannot sync; record the error and move on
- dabo.errorLog.write(_("File re-sync failed.
Reason: %s") % e)
+ dabo.log.error(_("File re-sync failed. Reason:
%s") % e)
def __del__(self):
@@ -405,7 +405,7 @@
self.uiApp.finish()
self.closeConnections()
self._tempFileHolder.release()
- dabo.infoLog.write(_("Application finished."))
+ dabo.log.info(_("Application finished."))
self._finished = True
self.afterFinish()
@@ -578,12 +578,12 @@
resp = urllib2.urlopen(url).read()
except urllib2.URLError, e:
# Could not connect
- dabo.errorLog.write(_("Could not connect to the
Dabo servers: %s") % e)
+ dabo.log.error(_("Could not connect to the Dabo
servers: %s") % e)
return e
except ValueError:
pass
except StandardError, e:
- dabo.errorLog.write(_("Failed to open URL
'%(url)s'. Error: %(e)s") % locals())
+ dabo.log.error(_("Failed to open URL '%(url)s'.
Error: %(e)s") % locals())
return e
if simplejson:
resp = simplejson.loads(resp)
@@ -604,7 +604,7 @@
resp = urllib2.urlopen(fileurl)
except StandardError, e:
# No internet access, or Dabo site is down.
- dabo.errorLog.write(_("Cannot access the Dabo site.
Error: %s") % e)
+ dabo.log.error(_("Cannot access the Dabo site. Error:
%s") % e)
self._resetWebUpdateCheck()
return None
@@ -621,7 +621,7 @@
delfiles = []
if not zipfiles:
# No updates available
- dabo.infoLog.write(_("No changed files available."))
+ dabo.log.info(_("No changed files available."))
return
projects = ("dabo", "demo", "ide")
prf = self._frameworkPrefs
@@ -728,7 +728,7 @@
newFile = resp.read()
if newFile:
file(pth, "w").write(newFile)
- dabo.infoLog.write(_("File %s updated") % pth)
+ dabo.log.info(_("File %s updated") % pth)
def updateFromSource(self, fileOrFiles):
@@ -939,7 +939,7 @@
for k,v in connDefs.items():
self.dbConnectionDefs[k] = v
- dabo.infoLog.write(_("%s database connection definition(s)
loaded.")
+ dabo.log.info(_("%s database connection definition(s) loaded.")
% (len(self.dbConnectionDefs)))
@@ -988,7 +988,7 @@
self.UI = "wx"
else:
# Custom app code or the dabo.ui module already set
this: don't touch
- dabo.infoLog.write(_("User interface already set to
'%s', so dApp didn't touch it.")
+ dabo.log.info(_("User interface already set to '%s', so
dApp didn't touch it.")
% self.UI)
@@ -997,7 +997,7 @@
try:
connDefs = importConnections(filePath, useHomeDir=True)
except SAXParseException, e:
- dabo.errorLog.write(_("Error parsing '%(filePath)s':
%(e)s") % locals())
+ dabo.log.error(_("Error parsing '%(filePath)s': %(e)s")
% locals())
return {}
# Convert the connect info dicts to dConnectInfo instances:
for k,v in connDefs.items():
@@ -1085,7 +1085,7 @@
"""
stdDirs = self._standardDirs + ("main.py", )
if dirname not in stdDirs:
- dabo.errorLog.write(_("Non-standard directory '%s'
requested") % dirname)
+ dabo.log.error(_("Non-standard directory '%s'
requested") % dirname)
return None
osp = os.path
if start is not None:
@@ -1324,7 +1324,7 @@
except AttributeError:
pass
if not ret:
- dabo.infoLog.write(_("WARNING: No BasePrefKey has been
set for this application."))
+ dabo.log.info(_("WARNING: No BasePrefKey has been set
for this application."))
try:
f = inspect.stack()[-1][1]
pth = os.path.abspath(f)
@@ -1356,21 +1356,24 @@
self._cryptoProvider = SimpleCrypt(key=val)
- def _getDatabaseActivityLog(self):
- return dabo.dbActivityLog.LogObject
+# def _getDatabaseActivityLog(self):
+# return dabo.dbActivityLog
+#
+# def _setDatabaseActivityLog(self, val):
+# try:
+# dbLogger = dabo.dbActivityLog
+# for hnd in dbLogger.handlers:
+# dbLogger.removeHandler(hnd)
+# dabo.dbLogHandler =
logging.handlers.RotatingFileHandler(filename=val,
+# maxBytes=dabo.maxLogFileSize,
encoding=self.Encoding)
+# dbLogger.addHandler(dabo.dbLogHandler)
+# dbLogger.setLevel(logging.INFO)
+# dabo.dbLogHandler.setLevel(logging.INFO)
+# except IOError, e:
+# dabo.log.error(_("Could not open file: '%(val)s':
%(e)s") % locals())
+# return
- def _setDatabaseActivityLog(self, val):
- if isinstance(val, basestring):
- try:
- f = open(val, "a")
- except IOError, e:
- dabo.errorLog.write(_("Could not open file:
'%(val)s': %(e)s") % locals())
- return
- else:
- f = val
- dabo.dbActivityLog.LogObject = f
-
def _getDefaultMenuBarClass(self):
try:
cls = self._defaultMenuBarClass
@@ -1445,7 +1448,7 @@
# instance of a raw
dApp. So the only thing we can really do is make the
# HomeDirectory the
location of the main script, since we can't guess at
# the application's
directory structure.
-
dabo.infoLog.write("Can't deduce HomeDirectory:setting to the script
directory.")
+ dabo.log.info("Can't
deduce HomeDirectory:setting to the script directory.")
hd = scriptDir
if os.path.split(hd)[1][-4:].lower() in (".zip",
".exe"):
@@ -1459,7 +1462,7 @@
if os.path.exists(val):
self._homeDirectory = os.path.abspath(val)
else:
- dabo.errorLog.write(_("Setting App HomeDirectory: Path
does not exist. '%s'") % val)
+ dabo.log.error(_("Setting App HomeDirectory: Path does
not exist. '%s'") % val)
def _getIcon(self):
@@ -1616,12 +1619,12 @@
if self.UI is None:
if uiType is None:
self._uiAlreadySet = True
- dabo.infoLog.write(_("User interface set set to
None."))
+ dabo.log.info(_("User interface set set to
None."))
elif dabo.ui.loadUI(uiType):
self._uiAlreadySet = True
- dabo.infoLog.write(_("User interface set to
'%s' by dApp.") % uiType)
+ dabo.log.info(_("User interface set to '%s' by
dApp.") % uiType)
else:
- dabo.infoLog.write(_("Tried to set UI to '%s',
but it failed.") % uiType)
+ dabo.log.info(_("Tried to set UI to '%s', but
it failed.") % uiType)
else:
raise RuntimeError(_("The UI cannot be reset once
assigned."))
@@ -1686,9 +1689,9 @@
each time this property is set, a new PyCrypto instance
is created, and
any previous crypto objects are released. Write-only.
(varies)"""))
- DatabaseActivityLog = property(_getDatabaseActivityLog,
_setDatabaseActivityLog, None,
- _("""Path to the file (or file-like object) to be used
for logging all database
- activity. Default=None, which means no log is kept.
(file or str)"""))
+# DatabaseActivityLog = property(_getDatabaseActivityLog,
_setDatabaseActivityLog, None,
+# _("""Path to the file (or file-like object) to be used
for logging all database
+# activity. Default=None, which means no log is kept.
(file or str)"""))
DefaultMenuBarClass = property(_getDefaultMenuBarClass,
_setDefaultMenuBarClass, None,
_("""The class used by all forms in the application
when no specific MenuBarClass
Modified: trunk/dabo/dEvents.py
===================================================================
--- trunk/dabo/dEvents.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/dEvents.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+import logging
import time
import dabo
from dabo.dObject import dObject
@@ -92,9 +93,12 @@
if eventName not in noLogEvents:
for logEventName in logEvents:
if logEventName.lower() == "all" or
logEventName == eventName:
- dabo.eventLog.write("dEvent Fired: %s
%s" %
+ holdLevel = dabo.log.level
+ dabo.log.setLevel(logging.INFO)
+ dabo.log.info("dEvent Fired: %s %s" %
(self._eventObject.getAbsoluteName(),
self.__class__.__name__,))
+ dabo.log.setLevel(holdLevel)
break
Modified: trunk/dabo/dLocalize.py
===================================================================
--- trunk/dabo/dLocalize.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/dLocalize.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -82,7 +82,7 @@
_currentTrans = daboTranslation.ugettext
except IOError:
# No translation file found
- dabo.errorLog.write("""
+ dabo.log.error("""
No translation file found for domain 'dabo'.
Locale dir = %s
Languages = %s
@@ -94,8 +94,8 @@
try:
translation = gettext.translation(domain, localedir,
languages=lang, codeset=charset)
except IOError:
- dabo.errorLog.write("No translation found for domain
'%s' and language %s." % (domain, lang))
- dabo.errorLog.write("""
+ dabo.log.error("No translation found for domain '%s'
and language %s." % (domain, lang))
+ dabo.log.error("""
No translation file found for domain '%s'.
Locale dir = %s
Languages = %s
Modified: trunk/dabo/dObject.py
===================================================================
--- trunk/dabo/dObject.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/dObject.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -251,7 +251,7 @@
compCode = compile(code, "", "exec")
except SyntaxError, e:
snm = self.Name
- dabo.errorLog.write(_("Method '%(nm)s' of
object '%(snm)s' has the following error: %(e)s") % locals())
+ dabo.log.error(_("Method '%(nm)s' of object
'%(snm)s' has the following error: %(e)s") % locals())
continue
# OK, we have the compiled code. Add it to the class
definition.
# NOTE: if the method name and the name in the 'def'
statement
Modified: trunk/dabo/dPref.py
===================================================================
--- trunk/dabo/dPref.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/dPref.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -17,7 +17,7 @@
# pkm: We can't use the errorLog to warn of this problem,
because errorLog
# descends from dObject, which needs to load dPref.py
first.
warnings.warn("Class dPref requires package 'pysqlite2'.")
- #dabo.errorLog.write("This class requires SQLite")
+ #dabo.log.error("This class requires SQLite")
# We don't want to deal with these as preferences.
regularAtts = ("AutoPersist", "__base__", "__bases__", "__basicsize__",
"__call__",
@@ -213,7 +213,7 @@
baseKey = self._getKey()
if not baseKey:
if not self._persistAll:
- dabo.errorLog.write(_("No base key set;
preference will not be persisted."))
+ dabo.log.error(_("No base key set; preference
will not be persisted."))
return
else:
key = att
@@ -223,7 +223,7 @@
try:
typ = self._typeDict[type(val)]
except KeyError:
- dabo.errorLog.write(_("BAD TYPE: %s") % type(val))
+ dabo.log.error(_("BAD TYPE: %s") % type(val))
typ = "?"
# Convert it to a string that can be properly converted back
val = self._encodeType(val, typ)
Modified: trunk/dabo/db/dBackend.py
===================================================================
--- trunk/dabo/db/dBackend.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/db/dBackend.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -202,21 +202,21 @@
def beginTransaction(self, cursor):
""" Begin a SQL transaction. Override in subclasses if
needed."""
self._connection.begin()
- dabo.dbActivityLog.write("SQL: begin")
+ dabo.dbActivityLog.info("SQL: begin")
return True
def commitTransaction(self, cursor):
""" Commit a SQL transaction."""
self._connection.commit()
- dabo.dbActivityLog.write("SQL: commit")
+ dabo.dbActivityLog.info("SQL: commit")
return True
def rollbackTransaction(self, cursor):
""" Roll back (revert) a SQL transaction."""
self._connection.rollback()
- dabo.dbActivityLog.write("SQL: rollback")
+ dabo.dbActivityLog.info("SQL: rollback")
return True
Modified: trunk/dabo/db/dConnectInfo.py
===================================================================
--- trunk/dabo/db/dConnectInfo.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/db/dConnectInfo.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -190,7 +190,7 @@
else:
raise ValueError("Invalid database
type: %s." % nm)
except ImportError:
- dabo.errorLog.write(_("You do not have the
database module for %s installed") % dbType)
+ dabo.log.error(_("You do not have the database
module for %s installed") % dbType)
self._dbType = None
self._backendObject = None
if _oldObject != self._backendObject:
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/db/dCursorMixin.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -255,7 +255,7 @@
return pythonType(field_val)
except Exception, e:
tfv = type(field_val)
-
dabo.infoLog.write(_("_correctFieldType() failed for field: '%(field_name)s';
value: '%(field_val)s'; type: '%(tfv)s'")
+ dabo.log.info(_("_correctFieldType()
failed for field: '%(field_name)s'; value: '%(field_val)s'; type: '%(tfv)s'")
% locals())
# Do the unicode conversion last:
@@ -276,7 +276,7 @@
if ok:
# change self.Encoding
and log the message
self.Encoding = enc
-
dabo.errorLog.write(_("Field %(fname)s: Incorrect unicode encoding set; using
'%(enc)s' instead")
+ dabo.log.error(_("Field
%(fname)s: Incorrect unicode encoding set; using '%(enc)s' instead")
%
{'fname':field_name, 'enc':enc} )
return ret
else:
@@ -286,7 +286,7 @@
# ret = field_val.tostring()
rfv = repr(field_val)
- dabo.errorLog.write(_("%(rfv)s couldn't be converted to
%(pythonType)s (field %(field_name)s)")
+ dabo.log.error(_("%(rfv)s couldn't be converted to
%(pythonType)s (field %(field_name)s)")
% locals())
return ret
@@ -309,16 +309,16 @@
res = self.superCursor.execute(self, sql,
params)
if not self.IsPrefCursor:
try:
- dabo.dbActivityLog.write("SQL:
%s, PARAMS: %s" % (
+ dabo.dbActivityLog.info("SQL:
%s, PARAMS: %s" % (
sql.decode(self.Encoding).replace("\n", " "),
', '.join("%s"
% p for p in params)))
except StandardError:
# A problem with writing to the
log, most likely due to encoding issues
-
dabo.dbActivityLog.write("FAILED SQL: %s")
+ dabo.dbActivityLog.info("FAILED
SQL: %s")
else:
res = self.superCursor.execute(self, sql)
if not self.IsPrefCursor:
- dabo.dbActivityLog.write("SQL: %s" % (
+ dabo.dbActivityLog.info("SQL: %s" % (
sql.decode(self.Encoding).replace("\n", " "),))
except Exception, e:
# There can be cases where errors are expected. In
those cases, the
@@ -328,14 +328,14 @@
raise e
if params:
try:
- dabo.dbActivityLog.write("FAILED SQL:
%s, PARAMS: %s" % (
+ dabo.dbActivityLog.info("FAILED SQL:
%s, PARAMS: %s" % (
sql.decode(self.Encoding).replace("\n", " "),
', '.join("%s" % p for
p in params)))
except StandardError:
# A problem with writing to the log,
most likely due to encoding issues
- dabo.dbActivityLog.write("FAILED SQL:
%s")
+ dabo.dbActivityLog.info("FAILED SQL:
%s")
else:
- dabo.dbActivityLog.write("FAILED SQL: %s" % (
+ dabo.dbActivityLog.info("FAILED SQL: %s" % (
sql.decode(self.Encoding).replace("\n", " "),))
# Database errors need to be decoded from database
encoding.
try:
@@ -350,7 +350,7 @@
elif "access" in errMsg.lower():
raise dException.DBNoAccessException(errMsg)
else:
- dabo.dbActivityLog.write(
+ dabo.dbActivityLog.info(
_("DBQueryException encountered
in execute(): %s\n%s") % (errMsg, sql))
raise dException.DBQueryException(errMsg)
@@ -375,7 +375,7 @@
errMsg = ustr(e).decode(self.Encoding)
except UnicodeError:
errMsg = unicode(e)
- dabo.errorLog.write("Error fetching records: %s" %
errMsg)
+ dabo.log.error("Error fetching records: %s" % errMsg)
if _records and not
self.BackendObject._alreadyCorrectedFieldTypes:
if isinstance(_records[0], (tuple, list)):
@@ -1003,7 +1003,7 @@
if not ignore:
sft, stv = ustr(fldType),
ustr(type(val))
msg = _("!!! Data Type Mismatch:
field=%(fld)s. Expecting: %(sft)s; got: %(stv)s") % locals()
- dabo.errorLog.write(msg)
+ dabo.log.error(msg)
# If the new value is different from the current value, change
it and also
# update the mementos if necessary.
@@ -1055,7 +1055,7 @@
else:
self._clearMemento(row)
else:
- dabo.infoLog.write("Field value changed, but
the memento"
+ dabo.log.info("Field value changed, but the
memento"
" can't be saved, because there
is no valid KeyField.")
# Finally, save the new value to the field:
@@ -1324,13 +1324,13 @@
errMsg = ustr(e).decode(self.Encoding)
except UnicodeError:
errMsg = unicode(e)
- dabo.dbActivityLog.write(
+ dabo.dbActivityLog.info(
_("DBQueryException encountered
in save(): %s") % errMsg)
raise e
except StandardError, e:
errMsg = ustr(e)
if "connect" in errMsg.lower():
- dabo.dbActivityLog.write(
+ dabo.dbActivityLog.info(
_("Connection Lost
exception encountered in saverow(): %s") % errMsg)
raise
dException.ConnectionLostException(errMsg)
else:
@@ -1760,8 +1760,8 @@
try:
newval = typ()
except Exception, e:
- dabo.errorLog.write(_("Failed to create
newval for field '%s'") % field_alias)
- dabo.errorLog.write(ustr(e))
+ dabo.log.error(_("Failed to create
newval for field '%s'") % field_alias)
+ dabo.log.error(ustr(e))
newval = u""
self._blank[field_alias] = newval
Modified: trunk/dabo/db/dDataSet.py
===================================================================
--- trunk/dabo/db/dDataSet.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/db/dDataSet.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -294,7 +294,7 @@
alias = "dataset"
if len(ds) == 0:
# Can't create and populate a table without a structure
- dabo.errorLog.write(_("Cannot populate without data for
alias '%s'")
+ dabo.log.error(_("Cannot populate without data for
alias '%s'")
% alias)
return None
hs = hashlib.md5(ustr(ds)).hexdigest()
Modified: trunk/dabo/db/dbFirebird.py
===================================================================
--- trunk/dabo/db/dbFirebird.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/db/dbFirebird.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -35,10 +35,10 @@
if kinterbasdb.__version__[0] == 3 and
kinterbasdb.__version__[1] >= 3:
# use type_conv=300 for blob encoding
kinterbasdb.init(type_conv=300)
-
dabo.dbActivityLog.write("kinterbasdb.init(type_conv=300)")
+
dabo.dbActivityLog.info("kinterbasdb.init(type_conv=300)")
else:
kinterbasdb.init(type_conv=200)
-
dabo.dbActivityLog.write("kinterbasdb.init(type_conv=200)")
+
dabo.dbActivityLog.info("kinterbasdb.init(type_conv=200)")
if initialized is None:
# Older versions of kinterbasedb didn't have
this attribute, so we write
# it ourselves:
@@ -209,7 +209,7 @@
ret = False
if not self._connection._has_transaction():
self._connection.begin()
- dabo.dbActivityLog.write("SQL: begin")
+ dabo.dbActivityLog.info("SQL: begin")
ret = True
return ret
@@ -219,7 +219,7 @@
to the database written to disk.
"""
self._connection.commit()
- dabo.dbActivityLog.write("SQL: commit")
+ dabo.dbActivityLog.info("SQL: commit")
def getLimitWord(self):
@@ -266,7 +266,7 @@
from rdb$database""" % gen
cursor.execute(sql)
ret = cursor.getFieldVal("nextval")
- dabo.dbActivityLog.write("SQL: result of pregenPK: %d" % ret)
+ dabo.dbActivityLog.info("SQL: result of pregenPK: %d" % ret)
return ret
Modified: trunk/dabo/db/dbMySQL.py
===================================================================
--- trunk/dabo/db/dbMySQL.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/db/dbMySQL.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -89,21 +89,21 @@
def beginTransaction(self, cursor):
""" Begin a SQL transaction."""
cursor.execute("START TRANSACTION")
- dabo.dbActivityLog.write("SQL: begin")
+ dabo.dbActivityLog.info("SQL: begin")
return True
def commitTransaction(self, cursor):
""" Commit a SQL transaction."""
cursor.execute("COMMIT")
- dabo.dbActivityLog.write("SQL: commit")
+ dabo.dbActivityLog.info("SQL: commit")
return True
def rollbackTransaction(self, cursor):
""" Rollback a SQL transaction."""
cursor.execute("ROLLBACK")
- dabo.dbActivityLog.write("SQL: rollback")
+ dabo.dbActivityLog.info("SQL: rollback")
return True
Modified: trunk/dabo/db/dbOracle.py
===================================================================
--- trunk/dabo/db/dbOracle.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/db/dbOracle.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -153,7 +153,7 @@
# used for testing
if not self._connection._has_transaction():
self._connection.begin()
- dabo.dbActivityLog.write("SQL: begin")
+ dabo.dbActivityLog.info("SQL: begin")
ret = True
return ret
Modified: trunk/dabo/db/dbPostgreSQL.py
===================================================================
--- trunk/dabo/db/dbPostgreSQL.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/db/dbPostgreSQL.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -86,17 +86,17 @@
try:
encoding = self._encodings[encoding]
except KeyError:
- dabo.dbActivityLog.write("unknown encoding %r" %
encoding)
+ dabo.dbActivityLog.info("unknown encoding %r" %
encoding)
if self._connection.encoding != encoding:
try:
self._connection.set_client_encoding(encoding)
except Exception:
- dabo.dbActivityLog.write("cannot set database
client encoding")
+ dabo.dbActivityLog.info("cannot set database
client encoding")
return encoding
def beginTransaction(self, cursor):
- dabo.dbActivityLog.write("SQL: begin (implicit, nothing done)")
+ dabo.dbActivityLog.info("SQL: begin (implicit, nothing done)")
return True
@@ -212,7 +212,7 @@
to the database written to disk.
"""
self.commitTransaction(cursor)
- dabo.dbActivityLog.write("SQL: Commit")
+ dabo.dbActivityLog.info("SQL: Commit")
def getLastInsertID(self, cursor):
Modified: trunk/dabo/db/dbSQLite.py
===================================================================
--- trunk/dabo/db/dbSQLite.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/db/dbSQLite.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -96,7 +96,7 @@
'begin' all the time, simply do nothing.
"""
cursor.execute("BEGIN")
- dabo.dbActivityLog.write("SQL: begin")
+ dabo.dbActivityLog.info("SQL: begin")
return True
@@ -105,7 +105,7 @@
opError = self.dbapi.OperationalError
try:
cursor.execute("COMMIT", errorClass=opError)
- dabo.dbActivityLog.write("SQL: commit")
+ dabo.dbActivityLog.info("SQL: commit")
return True
except opError, e:
# There is no transaction active in this case, so
ignore the error.
@@ -115,19 +115,19 @@
errMsg = ustr(e).decode(self.Encoding)
except UnicodeError:
errMsg = unicode(e)
- dabo.dbActivityLog.write("SQL: commit failed: %s" %
errMsg)
+ dabo.dbActivityLog.info("SQL: commit failed: %s" %
errMsg)
raise dException.DBQueryException(errMsg)
def rollbackTransaction(self, cursor):
""" Rollback a SQL transaction."""
cursor.execute("ROLLBACK")
- dabo.dbActivityLog.write("SQL: rollback")
+ dabo.dbActivityLog.info("SQL: rollback")
return True
def flush(self, crs):
- dabo.dbActivityLog.write("SQL: flush")
+ dabo.dbActivityLog.info("SQL: flush")
self._connection.commit()
Modified: trunk/dabo/lib/RemoteConnector.py
===================================================================
--- trunk/dabo/lib/RemoteConnector.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/lib/RemoteConnector.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -60,7 +60,7 @@
except urllib2.HTTPError, e:
if reRaise:
raise
- dabo.errorLog.write("HTTPError: %s" % e)
+ dabo.log.error("HTTPError: %s" % e)
return None
ret = res.read()
return ret
@@ -190,7 +190,7 @@
print dir(e)
errText = e.read()
errMsg = "\n".join(errText.splitlines()[4:])
- dabo.errorLog.write(_("HTTP Error getting app list:
%s") % e)
+ dabo.log.error(_("HTTP Error getting app list: %s") % e)
raise
# If they passed an app name, and it's in the returned app
list, run it
if path and (path in res):
@@ -256,7 +256,7 @@
# Nothing has changed on the server, so we're
cool...
return homedir
else:
- dabo.errorLog.write(_("HTTP Error syncing
files: %s") % e)
+ dabo.log.error(_("HTTP Error syncing files:
%s") % e)
return
except urllib2.URLError:
# Right now re-raise it and let the UI handle it
@@ -288,7 +288,7 @@
try:
res = self.UrlOpener.open(url)
except urllib2.HTTPError, e:
- dabo.errorLog.write(_("HTTP Error retrieving
files: %s") % e)
+ dabo.log.error(_("HTTP Error retrieving files:
%s") % e)
# res holds a zip file
f = StringIO(res.read())
zip = ZipFile(f)
Modified: trunk/dabo/lib/datanav/Page.py
===================================================================
--- trunk/dabo/lib/datanav/Page.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/lib/datanav/Page.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -430,7 +430,7 @@
elif typ == "bool":
chc = (_(CHOICE_TRUE), _(CHOICE_FALSE))
else:
- dabo.errorLog.write(_("Type '%s' not recognized.") %
typ)
+ dabo.log.error(_("Type '%s' not recognized.") % typ)
chc = ()
return chc
Modified: trunk/dabo/lib/logger.py
===================================================================
--- trunk/dabo/lib/logger.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/lib/logger.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -14,10 +14,10 @@
messages.
So, to display general informational messages, call:
- dabo.infoLog.write("message")
+ dabo.log.info("message")
For error messages, call:
- dabo.errorLog.write("message")
+ dabo.log.error("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
Added: trunk/dabo/logging.conf
===================================================================
--- trunk/dabo/logging.conf (rev 0)
+++ trunk/dabo/logging.conf 2010-08-22 20:17:38 UTC (rev 5958)
@@ -0,0 +1,49 @@
+[loggers]
+keys=root, daboLog, dbActivity
+
+[handlers]
+keys=consoleHandler, fileHandler, dbHandler
+
+[formatters]
+keys=basicFormatter
+
+[logger_root]
+level=DEBUG
+handlers=consoleHandler
+
+[logger_daboLog]
+level=DEBUG
+handlers=consoleHandler, fileHandler
+qualname=dabo.mainLog
+propagate=0
+
+[logger_dbActivity]
+level=DEBUG
+handlers=dbHandler
+qualname=dabo.dbActivityLog
+propagate=0
+
+[handler_consoleHandler]
+class=StreamHandler
+level=ERROR
+formatter=basicFormatter
+args=(sys.stdout, )
+
+[handler_fileHandler]
+class=handlers.RotatingFileHandler
+level=ERROR
+formatter=basicFormatter
+args=("dabo.log", "a", 5242880, 7, "utf8")
+
+[handler_dbHandler]
+class=handlers.RotatingFileHandler
+level=DEBUG
+formatter=basicFormatter
+### The default is to discard db log messages.
+### Uncomment the second args line to add db logging.
+args=(os.devnull, "a", 5242880, 7, "utf8")
+# args=("db_activity.log", "a", 5242880, 7, "utf8")
+
+[formatter_basicFormatter]
+format=%(asctime)s - %(levelname)s - %(message)s
+datefmt=%Y-%m-%d %H:%M:%S
Modified: trunk/dabo/settings.py
===================================================================
--- trunk/dabo/settings.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/settings.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -2,6 +2,7 @@
import os
import sys
+import logging
# Dabo Global Settings
@@ -179,9 +180,28 @@
# URL of the Web Update server
webupdate_urlbase = "http://daboserver.com/webupdate"
+########################################################
+#### The commented out code was a first attempt at using Python logging, but
with
+#### the dabo.settings file being used to configure instead of logging.conf
+########################################################
+# Logging settings
+# logLevel = logging.DEBUG
+# logFile = "dabo.log"
+# logConsoleLevel = logging.ERROR
+# logFileLevel = logging.ERROR
+# logName = "DaboLog"
+# consoleFormat = "%(asctime)s - %(levelname)s - %(message)s"
+# fileFormat = "%(asctime)s - %(levelname)s - %(message)s"
+# # Set the db file to the null device initially
+# dbLogFile = os.devnull
+# dbLogFileLevel = logging.DEBUG
+# maxLogFileSize = 5242880 # 5 MB
+########################################################
+
### Settings - end
+
# Make sure that the current directory is in the sys.path
sys.path.append(os.getcwd())
Modified: trunk/dabo/ui/__init__.py
===================================================================
--- trunk/dabo/ui/__init__.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/ui/__init__.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -67,7 +67,7 @@
# No problem; just a redundant call
pass
else:
- dabo.infoLog.write(_("Cannot change the uiType to
'%(typ)s', because UI '%(currType)s' is already loaded.")
+ dabo.log.info(_("Cannot change the uiType to '%(typ)s',
because UI '%(currType)s' is already loaded.")
% locals())
return retVal
@@ -84,7 +84,7 @@
__defaultUI = None
if __defaultUI:
- dabo.infoLog.write(_("Automatically loading default ui '%s'...") %
__defaultUI)
+ dabo.log.info(_("Automatically loading default ui '%s'...") %
__defaultUI)
# For now, don't do the tempting option:
#loadUI(defaultUI)
# ...unless it will work with single-file installers. I think that
@@ -94,7 +94,7 @@
from uiwx import *
else:
pass
- #dabo.infoLog.write(_("No default UI set. (DABO_DEFAULT_UI)"))
+ #dabo.log.info(_("No default UI set. (DABO_DEFAULT_UI)"))
Modified: trunk/dabo/ui/dDataControlMixinBase.py
===================================================================
--- trunk/dabo/ui/dDataControlMixinBase.py 2010-08-20 12:19:05 UTC (rev
5957)
+++ trunk/dabo/ui/dDataControlMixinBase.py 2010-08-22 20:17:38 UTC (rev
5958)
@@ -246,7 +246,7 @@
try:
exec ("src.%s =
curVal" % self.DataField)
except StandardError, e:
-
dabo.errorLog.write("Could not bind to '%s.%s'\nReason: %s" % (self.DataSource,
self.DataField, e) )
+
dabo.log.error("Could not bind to '%s.%s'\nReason: %s" % (self.DataSource,
self.DataField, e) )
else:
# The source is a
direct object reference
try:
@@ -256,7 +256,7 @@
nm =
self.DataSource._name
else:
nm =
ustr(self.DataSource)
-
dabo.errorLog.write("Could not bind to '%s.%s'\nReason: %s" % (nm,
self.DataField, e) )
+
dabo.log.error("Could not bind to '%s.%s'\nReason: %s" % (nm, self.DataField,
e) )
self._oldVal = curVal
self._from_flushValue = True
self._afterValueChanged()
@@ -310,7 +310,7 @@
elif isinstance(value, bool):
return "L"
else:
- dabo.infoLog.write(_("getShortDataType - unknown type:
%s") % (value,))
+ dabo.log.info(_("getShortDataType - unknown type: %s")
% (value,))
return "?"
@@ -458,7 +458,7 @@
self.__src = ds
if not isinstance(ds, (dObject, dPref)):
# Warn about possible
unsupported behavior.
-
dabo.infoLog.write(_("DataSource '%s' does not inherit from a proper Dabo
class. This may result in unsupported problems.") % ds.__repr__())
+ dabo.log.info(_("DataSource
'%s' does not inherit from a proper Dabo class. This may result in unsupported
problems.") % ds.__repr__())
else:
self._srcIsBizobj =
isinstance(ds, dabo.biz.dBizobj)
return self.__src
Modified: trunk/dabo/ui/uitk/__init__.py
===================================================================
--- trunk/dabo/ui/uitk/__init__.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/ui/uitk/__init__.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -3,7 +3,7 @@
import dabo.ui
from uiApp import uiApp
-dabo.infoLog.write("The Tkinter module is experimental only, and doesn't work.
You've been warned.")
+dabo.log.info("The Tkinter module is experimental only, and doesn't work.
You've been warned.")
uiType = {'shortName': 'tk', 'moduleName': 'uitk', 'longName': 'Tkinter'}
_uiApp = None
Modified: trunk/dabo/ui/uitk/dFormMixin.py
===================================================================
--- trunk/dabo/ui/uitk/dFormMixin.py 2010-08-20 12:19:05 UTC (rev 5957)
+++ trunk/dabo/ui/uitk/dFormMixin.py 2010-08-22 20:17:38 UTC (rev 5958)
@@ -50,7 +50,7 @@
# bo = self.getBizobj()
# exec(self.debugText)
# except:
-# dabo.infoLog.write(_("Could not execute: %s") %
self.debugText)
+# dabo.log.info(_("Could not execute: %s") %
self.debugText)
# dlg.Destroy()
#
#
Modified: trunk/dabo/ui/uitk/dPemMixin.py
===================================================================
---
(38545 bytes were truncated as it was too long for the email (max 40000 bytes.)
_______________________________________________
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]