Changeset 5962

Show
Ignore:
Timestamp:
08/26/2010 05:42:26 AM (1 year ago)
Author:
ed
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/__init__.py

    r5958 r5962  
    128128from settings import * 
    129129 
     130# See if a logging.conf file exists in either the current directory or 
     131# the base directory for the dabo module. If such a file is found, use 
     132# it to configure logging. Otherwise, use the values gotten from 
     133# dabo.settings. 
    130134_logConfFileName = "logging.conf" 
    131 logConfFile = os.path.join(os.getcwd(), _logConfFileName) 
    132 if not os.path.exists(logConfFile): 
    133     daboloc = os.path.dirname(__file__) 
    134     logConfFile = os.path.join(daboloc, _logConfFileName) 
    135 import logging.config 
    136 logging.config.fileConfig(logConfFile) 
    137  
    138 log = logging.getLogger("dabo.mainLog") 
    139 dbActivityLog = logging.getLogger("dabo.dbActivityLog") 
    140 consoleLog = fileLog = dbLog = None 
    141 for _handler in log.handlers: 
    142     try: 
    143         _handler.baseFilename 
    144         fileLog = _handler 
    145     except AttributeError: 
    146         consoleLog = _handler 
    147 for _handler in dbActivityLog.handlers: 
    148     try: 
    149         _handler.baseFilename 
    150         dbLog = _handler 
    151         break 
    152     except AttributeError: 
    153         pass 
     135_hasConfFile = False 
     136_logConfFile = os.path.join(os.getcwd(), _logConfFileName) 
     137if not os.path.exists(_logConfFile): 
     138    _daboloc = os.path.dirname(__file__) 
     139    _logConfFile = os.path.join(_daboloc, _logConfFileName) 
     140if os.path.exists(_logConfFile): 
     141    import logging.config 
     142    logging.config.fileConfig(_logConfFile) 
     143    # Populate the module namespace with the appropriate loggers 
     144    log = logging.getLogger(mainLogQualName) 
     145    dbActivityLog = logging.getLogger(dbLogQualName) 
     146    consoleLog = fileLog = dbLog = None 
     147    for _handler in log.handlers: 
     148        try: 
     149            _handler.baseFilename 
     150            fileLog = _handler 
     151        except AttributeError: 
     152            consoleLog = _handler 
     153    for _handler in dbActivityLog.handlers: 
     154        try: 
     155            _handler.baseFilename 
     156            dbLog = _handler 
     157            break 
     158        except AttributeError: 
     159            pass 
     160else: 
     161    # Use dabo.settings values to configure the logs 
     162    consoleLog = logging.StreamHandler() 
     163    consoleLog.setLevel(mainLogConsoleLevel) 
     164    fileLog = logging.handlers.RotatingFileHandler(filename=mainLogFile, maxBytes=maxLogFileSize, 
     165            encoding=defaultEncoding) 
     166    fileLog.setLevel(mainLogFileLevel) 
     167    consoleFormatter = logging.Formatter(consoleFormat) 
     168    consoleFormatter.datefmt = mainLogDateFormat 
     169    fileFormatter = logging.Formatter(fileFormat) 
     170    fileFormatter.datefmt = mainLogDateFormat 
     171    consoleLog.setFormatter(consoleFormatter) 
     172    fileLog.setFormatter(fileFormatter) 
     173    log = logging.getLogger(mainLogQualName) 
     174    log.setLevel(logging.DEBUG) 
     175    log.addHandler(consoleLog) 
     176    log.addHandler(fileLog) 
     177     
     178    dbActivityLog = logging.getLogger(dbLogQualName) 
     179    dbLog = logging.handlers.RotatingFileHandler(filename=dbLogFile, maxBytes=maxLogFileSize, 
     180            encoding=defaultEncoding) 
     181    dbActivityLog.addHandler(dbLog) 
     182    dbActivityLog.setLevel(dbLogFileLevel) 
     183    dbLog.setLevel(dbLogFileLevel) 
    154184 
    155185 
     
    158188#### the dabo.settings file being used to configure instead of logging.conf 
    159189######################################################## 
    160 # logConsoleHandler = logging.StreamHandler() 
    161 # logConsoleHandler.setLevel(logConsoleLevel) 
    162 # logFileHandler = logging.handlers.RotatingFileHandler(filename=logFile, maxBytes=maxLogFileSize, 
    163 #       encoding=defaultEncoding) 
    164 # logFileHandler.setLevel(logFileLevel) 
    165 # consoleFormatter = logging.Formatter(consoleFormat) 
    166 # fileFormatter = logging.Formatter(fileFormat) 
    167 # logConsoleHandler.setFormatter(consoleFormatter) 
    168 # logFileHandler.setFormatter(fileFormatter) 
    169 # log = logging.getLogger(logName) 
    170 # log.setLevel(logging.DEBUG) 
    171 # log.addHandler(logConsoleHandler) 
    172 # log.addHandler(logFileHandler) 
    173 #  
    174 # This log is set to the null output device ('nul' on Windows; /dev/null on the rest) 
    175 # dbActivityLog = logging.getLogger("dabo.dbActivityLog") 
    176 # dbLogHandler = logging.handlers.RotatingFileHandler(filename=dbLogFile, maxBytes=maxLogFileSize, 
    177 #       encoding=defaultEncoding) 
    178 # dbActivityLog.addHandler(dbLogHandler) 
    179 # dbActivityLog.setLevel(dbLogFileLevel) 
    180 # dbLogHandler.setLevel(dbLogFileLevel) 
    181190######################################################## 
    182191 
  • trunk/dabo/settings.py

    r5958 r5962  
    181181webupdate_urlbase = "http://daboserver.com/webupdate" 
    182182 
    183 ######################################################## 
    184 #### The commented out code was a first attempt at using Python logging, but with 
    185 #### the dabo.settings file being used to configure instead of logging.conf 
    186 ######################################################## 
    187183# Logging settings 
    188 # logLevel = logging.DEBUG 
    189 # logFile = "dabo.log" 
    190 # logConsoleLevel = logging.ERROR 
    191 # logFileLevel = logging.ERROR 
    192 # logName = "DaboLog" 
    193 # consoleFormat = "%(asctime)s - %(levelname)s - %(message)s" 
    194 # fileFormat = "%(asctime)s - %(levelname)s - %(message)s" 
    195 # # Set the db file to the null device initially 
    196 # dbLogFile = os.devnull 
    197 # dbLogFileLevel = logging.DEBUG 
    198 # maxLogFileSize = 5242880      # 5 MB 
    199 ######################################################## 
     184mainLogLevel = logging.DEBUG 
     185mainLogQualName = "dabo.mainLog" 
     186# Set the main log file to the null device initially 
     187mainLogFile = os.devnull 
     188mainLogConsoleLevel = logging.ERROR 
     189mainLogFileLevel = logging.ERROR 
     190mainLogDateFormat = "%Y-%m-%d %H:%M:%S" 
     191consoleFormat = "%(asctime)s - %(levelname)s - %(message)s" 
     192fileFormat = "%(asctime)s - %(levelname)s - %(message)s" 
     193# Set the db file to the null device initially 
     194dbLogFile = os.devnull 
     195dbLogQualName = "dabo.dbActivityLog" 
     196dbLogFileLevel = logging.DEBUG 
     197maxLogFileSize = 5242880        # 5 MB 
    200198 
    201199