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
8
9
10
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
23 logLineFormat = "%(asctime)s [%(levelname)s %(process)s] %(message)s"
24
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")
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")
55
56 @listensTo("Warning")
58 self.infoLogger.warning(message)
59
60 @listensTo("Error")
63