dabo Commit
Revision 5962
Date: 2010-08-26 05:42:26 -0700 (Thu, 26 Aug 2010)
Author: Ed
Trac: http://trac.dabodev.com/changeset/5962
Changed:
U trunk/dabo/__init__.py
D trunk/dabo/logging.conf
A trunk/dabo/logging.conf.sample
U trunk/dabo/settings.py
Log:
Updated the logging changes so that by default, the values in dabo.settings are
used to configure logging. If a file named 'logging.conf' exists in either the
current directory or the base directory of the framework, it will be used
instead, and the values in dabo.settings will be ignored.
Renamed the logging.conf file added in the last commit to
'logging.conf.sample', so that people who want to use conf file configuration
have something to start with.
Diff:
Modified: trunk/dabo/__init__.py
===================================================================
--- trunk/dabo/__init__.py 2010-08-22 23:25:44 UTC (rev 5961)
+++ trunk/dabo/__init__.py 2010-08-26 12:42:26 UTC (rev 5962)
@@ -127,57 +127,66 @@
# we want to make them part of the dabo namespace.
from settings import *
+# See if a logging.conf file exists in either the current directory or
+# the base directory for the dabo module. If such a file is found, use
+# it to configure logging. Otherwise, use the values gotten from
+# dabo.settings.
_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)
+_hasConfFile = False
+_logConfFile = os.path.join(os.getcwd(), _logConfFileName)
+if not os.path.exists(_logConfFile):
+ _daboloc = os.path.dirname(__file__)
+ _logConfFile = os.path.join(_daboloc, _logConfFileName)
+if os.path.exists(_logConfFile):
+ import logging.config
+ logging.config.fileConfig(_logConfFile)
+ # Populate the module namespace with the appropriate loggers
+ log = logging.getLogger(mainLogQualName)
+ dbActivityLog = logging.getLogger(dbLogQualName)
+ 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
+else:
+ # Use dabo.settings values to configure the logs
+ consoleLog = logging.StreamHandler()
+ consoleLog.setLevel(mainLogConsoleLevel)
+ fileLog = logging.handlers.RotatingFileHandler(filename=mainLogFile,
maxBytes=maxLogFileSize,
+ encoding=defaultEncoding)
+ fileLog.setLevel(mainLogFileLevel)
+ consoleFormatter = logging.Formatter(consoleFormat)
+ consoleFormatter.datefmt = mainLogDateFormat
+ fileFormatter = logging.Formatter(fileFormat)
+ fileFormatter.datefmt = mainLogDateFormat
+ consoleLog.setFormatter(consoleFormatter)
+ fileLog.setFormatter(fileFormatter)
+ log = logging.getLogger(mainLogQualName)
+ log.setLevel(logging.DEBUG)
+ log.addHandler(consoleLog)
+ log.addHandler(fileLog)
+
+ dbActivityLog = logging.getLogger(dbLogQualName)
+ dbLog = logging.handlers.RotatingFileHandler(filename=dbLogFile,
maxBytes=maxLogFileSize,
+ encoding=defaultEncoding)
+ dbActivityLog.addHandler(dbLog)
+ dbActivityLog.setLevel(dbLogFileLevel)
+ dbLog.setLevel(dbLogFileLevel)
-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
Deleted: trunk/dabo/logging.conf
Added: trunk/dabo/logging.conf.sample
===================================================================
--- trunk/dabo/logging.conf.sample (rev 0)
+++ trunk/dabo/logging.conf.sample 2010-08-26 12:42:26 UTC (rev 5962)
@@ -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=INFO
+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-22 23:25:44 UTC (rev 5961)
+++ trunk/dabo/settings.py 2010-08-26 12:42:26 UTC (rev 5962)
@@ -180,23 +180,21 @@
# 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
-########################################################
+mainLogLevel = logging.DEBUG
+mainLogQualName = "dabo.mainLog"
+# Set the main log file to the null device initially
+mainLogFile = os.devnull
+mainLogConsoleLevel = logging.ERROR
+mainLogFileLevel = logging.ERROR
+mainLogDateFormat = "%Y-%m-%d %H:%M:%S"
+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
+dbLogQualName = "dabo.dbActivityLog"
+dbLogFileLevel = logging.DEBUG
+maxLogFileSize = 5242880 # 5 MB
### Settings - end
_______________________________________________
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]