Changeset 06b07f in indico
- Timestamp:
- 08/31/10 07:47:46 (3 years ago)
- Branches:
- master, burotel, hello-world-walkthrough, ipv6, new-webex, v0.97-series, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, d9941f8582b36b24821a11ea5ba16fda6a457fb1
- Children:
- b40a31
- Parents:
- e73bb6
- git-author:
- Ian Rolewicz <ian.rolewicz@…> (05/25/10 16:15:40)
- git-committer:
- Jose Benito <jose.benito.gonzalez@…> (08/31/10 07:47:46)
- Files:
-
- 1 added
- 5 edited
-
etc/logging.conf.sample (added)
-
indico/MaKaC/common/logger.py (modified) (3 diffs)
-
indico/MaKaC/common/mail.py (modified) (4 diffs)
-
indico/MaKaC/consoleScripts/installBase.py (modified) (1 diff)
-
indico/MaKaC/plugins/RoomBooking/default/dalManager.py (modified) (7 diffs)
-
setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
indico/MaKaC/common/logger.py
rfb9bd3 r06b07f 1 import os, logging 1 import os, logging.config 2 2 import logging.handlers 3 3 4 4 from MaKaC.common.Configuration import Config 5 import ConfigParser 5 6 6 7 class ExtraIndicoFilter(logging.Filter): … … 11 12 return 1 12 13 14 class LoggerUtils: 15 16 @classmethod 17 def configFromFile(self, fname, defaultArgs, filters): 18 """ 19 Read the logging configuration from the logging.conf file. 20 Fetch default values if the logging.conf file is not set. 21 """ 22 23 if not os.path.exists(fname): 24 return 25 26 cp = ConfigParser.ConfigParser() 27 if hasattr(cp, 'readfp') and hasattr(fname, 'readline'): 28 cp.readfp(fname) 29 else: 30 cp.read(fname) 31 32 formatters = logging.config._create_formatters(cp) 33 34 logging._acquireLock() 35 try: 36 logging._handlers.clear() 37 del logging._handlerList[:] 38 handlers = self._install_handlers(cp, defaultArgs, formatters, filters) 39 try: 40 logging.config._install_loggers(cp, handlers) 41 except TypeError: 42 logging.config._install_loggers(cp, handlers, False) 43 44 finally: 45 logging._releaseLock() 46 47 @classmethod 48 def _install_handlers(self, cp, defaultArgs, formatters, filters = None): 49 """ 50 Install and return handlers. If a handler configuration 51 is missing its args, fetches the default values from the 52 indico.conf file 53 """ 54 hlist = cp.get("handlers", "keys") 55 if not len(hlist): 56 return {} 57 hlist = hlist.split(",") 58 handlers = {} 59 fixups = [] #for inter-handler references 60 61 for hand in hlist: 62 sectname = "handler_%s" % hand.strip() 63 klass = cp.get(sectname, "class") 64 opts = cp.options(sectname) 65 if "formatter" in opts: 66 fmt = cp.get(sectname, "formatter") 67 else: 68 fmt = "" 69 klass = eval(klass, vars(logging)) 70 if "args" in opts : 71 # if the args are not present in the file, 72 # take default values 73 args = cp.get(sectname, "args") 74 else : 75 try: 76 args = defaultArgs[hand.strip()] 77 except KeyError: 78 continue 79 args = eval(args, vars(logging)) 80 h = apply(klass, args) 81 if "level" in opts: 82 level = cp.get(sectname, "level") 83 h.setLevel(logging._levelNames[level]) 84 if len(fmt): 85 h.setFormatter(formatters[fmt]) 86 if filters and hand.strip() in filters: 87 for fltr in filters[hand.strip()]: 88 h.addFilter(fltr) 89 #temporary hack for FileHandler and MemoryHandler. 90 if klass == logging.handlers.MemoryHandler: 91 if "target" in opts: 92 target = cp.get(sectname,"target") 93 else: 94 target = "" 95 if len(target): #the target handler may not be loaded yet, so keep for later... 96 fixups.append((h, target)) 97 handlers[hand] = h 98 #now all handlers are loaded, fixup inter-handler references... 99 for h, t in fixups: 100 h.setTarget(handlers[t]) 101 return handlers 102 13 103 class Logger: 14 104 """ … … 18 108 config = Config.getInstance() 19 109 20 __rootLogger = logging.getLogger('') 21 22 __indicoFileHandler = logging.FileHandler(os.path.join(config.getLogDir(), 'indico.log'),'a') 23 __otherFileHandler = logging.FileHandler(os.path.join(config.getLogDir(), 'other.log'),'a') 24 25 __formatter = logging.Formatter('%(asctime)s %(name)-16s: %(levelname)-8s %(message)s') 26 __indicoFileHandler.setFormatter(__formatter) 27 __otherFileHandler.setFormatter(__formatter) 28 __indicoFileHandler.addFilter(logging.Filter('indico')) 29 __otherFileHandler.addFilter(ExtraIndicoFilter()) 30 110 configDir = config.getLogDir() 111 smtpServer = config.getSmtpServer() 31 112 serverName = config.getWorkerName() 32 113 if not serverName: 33 114 serverName = config.getHostNameURL() 34 115 35 # TODO: add config option to disable this? 36 __smtpHandler = logging.handlers.SMTPHandler(config.getSmtpServer(), 37 'logger@%s' % serverName, 38 config.getSupportEmail(), 39 'Unexpected Exception occurred at %s' % serverName) 116 # Default arguments for the handlers, taken mostly for the configuration 117 defaultArgs = { 'indico' : "('%s', 'a')" %os.path.join(configDir, 'indico.log'), 118 'other' : "('%s', 'a')" %os.path.join(configDir, 'other.log'), 119 'smtp' : "('%s', 'logger@%s', ['%s'], 'Unexpected Exception occurred at %s')" 120 %(smtpServer, serverName, config.getSupportEmail(), serverName) 121 } 40 122 41 __smtpHandler.addFilter(logging.Filter('indico')) 42 __smtpHandler.setLevel(logging.ERROR) 43 __smtpHandler.setFormatter(logging.Formatter("%(asctime)s %(name)s - %(levelname)s %(filename)s:%(lineno)d\n\n%(message)s")) 123 # Lists of filters for each handler 124 filters = {'indico' : [logging.Filter('indico')], 125 'other' : [ExtraIndicoFilter()], 126 'smtp' : [logging.Filter('indico')]} 44 127 45 __rootLogger.addHandler(__indicoFileHandler) 46 __rootLogger.addHandler(__otherFileHandler) 47 __otherFileHandler.setLevel(logging.WARNING) 48 __rootLogger.addHandler(__smtpHandler) 128 logConfFilepath = os.path.join(config.getConfigurationDir(), "logging.conf") 49 129 50 # TODO: see savannah task 51 # if it's debug mode, be more exhaustive 52 #if DEBUG or HelperMaKaCInfo.getMaKaCInfoInstance().isDebugActive(): 53 # __rootLogger.setLevel(logging.DEBUG) 54 #else: 55 # __rootLogger.setLevel(logging.WARNING) 56 57 __rootLogger.setLevel(logging.DEBUG) 130 #logging.config.fileConfig(logConfFilepath) 131 LoggerUtils.configFromFile(logConfFilepath, defaultArgs, filters) 58 132 59 133 @classmethod -
indico/MaKaC/common/mail.py
rbdd862 r06b07f 26 26 from MaKaC.common.logger import Logger 27 27 28 from MaKaC.common.logger import Logger29 30 28 class GenericMailer: 31 29 … … 51 49 if len(cc) == 0 : 52 50 notification.getCCList().remove(cc) 53 51 54 52 to=", ".join(notification.getToList()) 55 53 # raise to … … 74 72 75 73 Logger.get('mail').debug('Mail sent to %s' % to) 76 74 77 75 def sendAndLog(notification, conference, module="", user = None): 78 76 GenericMailer.send(notification) … … 86 84 except: 87 85 logData["toList"] = notification.getToList() 88 logData["ccList"] = notification._ccList 86 logData["ccList"] = notification._ccList 89 87 try: 90 88 logData["subject"] = notification._subject -
indico/MaKaC/consoleScripts/installBase.py
r89b48e r06b07f 514 514 # copy the db config files 515 515 for f in [xx for xx in ('%s/zdctl.conf' % targetDirs['etc'], 516 '%s/zodb.conf' % targetDirs['etc']) if not os.path.exists(xx)]: 516 '%s/zodb.conf' % targetDirs['etc'], 517 '%s/logging.conf' %targetDirs['etc']) if not os.path.exists(xx)]: 517 518 shutil.copy('%s.sample' % f, f) 518 519 -
indico/MaKaC/plugins/RoomBooking/default/dalManager.py
rbdd862 r06b07f 50 50 else: 51 51 return False 52 52 53 53 @staticmethod 54 54 def theInstance(): … … 73 73 @staticmethod 74 74 def getRoot(name=""): 75 75 76 if name == "": 76 77 return DALManager.root … … 91 92 else: 92 93 raise MaKaCError("Cannot connect to the room booking database") 93 94 94 95 @staticmethod 95 96 def connect(): … … 100 101 DALManager.connection = DALManager.theInstance().db.open() 101 102 DALManager.root = DALManager.connection.root() 102 103 103 104 @staticmethod 104 105 def disconnect(): … … 109 110 DALManager.root = None 110 111 DALManager.connection = None 111 112 112 113 @staticmethod 113 114 def commit(): … … 116 117 if DALManager.isConnected(): 117 118 DALManager.connection.transaction_manager.get().commit() 118 119 119 120 @staticmethod 120 121 def rollback(): … … 136 137 return 137 138 DALManager.theInstance().db.pack(days=days) 138 139 -
setup.py
r89b48e r06b07f 245 245 shutil.copy('etc/indico.conf.sample', local) 246 246 247 for f in [x for x in ('etc/zdctl.conf', 'etc/zodb.conf' ) if not os.path.exists(x)]:247 for f in [x for x in ('etc/zdctl.conf', 'etc/zodb.conf', 'etc/logging.conf') if not os.path.exists(x)]: 248 248 shutil.copy('%s.sample' % f, f) 249 249
Note: See TracChangeset
for help on using the changeset viewer.
