Package gavo :: Package user :: Module logui
[frames] | no frames]

Source Code for Module gavo.user.logui

 1  """ 
 2  An observer doing logging of warnings, infos, errors, etc. 
 3   
 4  No synchronization takes place; it's probably not worth sweating this. 
 5  """ 
 6   
 7  #c Copyright 2008-2019, the GAVO project 
 8  #c 
 9  #c This program is free software, covered by the GNU GPL.  See the 
10  #c COPYING file in the source distribution. 
11   
12   
13  import logging 
14  import os 
15   
16  from gavo import base 
17  from gavo import utils 
18  from gavo.base import ObserverBase, listensTo 
19  from gavo.protocols.gavolog import RotatingFileHandler 
20 21 22 -class LoggingUI(ObserverBase):
23 logLineFormat = "%(asctime)s [%(levelname)s %(process)s] %(message)s" 24
25 - def __init__(self, eh):
26 ObserverBase.__init__(self, eh) 27 errH = RotatingFileHandler( 28 os.path.join(base.getConfig("logDir"), "dcErrors"), 29 maxBytes=500000, backupCount=3, mode=0664) 30 errH.setFormatter( 31 logging.Formatter(self.logLineFormat)) 32 self.errorLogger = logging.getLogger("dcErrors") 33 self.errorLogger.addHandler(errH) 34 self.errorLogger.propagate = False 35 36 infoH = RotatingFileHandler( 37 os.path.join(base.getConfig("logDir"), "dcInfos"), 38 maxBytes=500000, backupCount=1, mode=0664) 39 infoH.setFormatter(logging.Formatter(self.logLineFormat)) 40 self.infoLogger = logging.getLogger("dcInfos") 41 self.infoLogger.propagate = False 42 self.infoLogger.addHandler(infoH) 43 self.infoLogger.setLevel(logging.DEBUG)
44 45 @listensTo("ExceptionMutation")
46 - def logOldException(self, res):
47 if base.DEBUG: 48 excInfo, newExc = res 49 self.infoLogger.info("Swallowed the exception below, re-raising %s"% 50 str(newExc), exc_info=excInfo)
51 52 @listensTo("Info")
53 - def logInfo(self, message):
54 self.infoLogger.info(message)
55 56 @listensTo("Warning")
57 - def logWarning(self, message):
58 self.infoLogger.warning(message)
59 60 @listensTo("Error")
61 - def logError(self, message):
62 self.errorLogger.error(utils.safe_str(message), exc_info=True)
63