Package haizea :: Package core :: Module log
[hide private]
[frames] | no frames]

Source Code for Module haizea.core.log

 1  # -------------------------------------------------------------------------- # 
 2  # Copyright 2006-2009, University of Chicago                                 # 
 3  # Copyright 2008-2009, Distributed Systems Architecture Group, Universidad   # 
 4  # Complutense de Madrid (dsa-research.org)                                   # 
 5  #                                                                            # 
 6  # Licensed under the Apache License, Version 2.0 (the "License"); you may    # 
 7  # not use this file except in compliance with the License. You may obtain    # 
 8  # a copy of the License at                                                   # 
 9  #                                                                            # 
10  # http://www.apache.org/licenses/LICENSE-2.0                                 # 
11  #                                                                            # 
12  # Unless required by applicable law or agreed to in writing, software        # 
13  # distributed under the License is distributed on an "AS IS" BASIS,          # 
14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   # 
15  # See the License for the specific language governing permissions and        # 
16  # limitations under the License.                                             # 
17  # -------------------------------------------------------------------------- # 
18   
19  import logging 
20  import sys 
21  from haizea.common.utils import get_clock 
22  from haizea.common.constants import LOGLEVEL_VDEBUG, LOGLEVEL_STATUS 
23   
24  logging.addLevelName(LOGLEVEL_VDEBUG, "VDEBUG") 
25  logging.addLevelName(LOGLEVEL_STATUS, "STATUS") 
26   
27  # Custom logger that uses our log record 
28 -class HaizeaLogger(logging.Logger):
29
30 - def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func=None, extra=None):
31 # Modify "extra" parameter keyword 32 try: 33 haizeatime = get_clock().get_time() 34 except: 35 # This is a kludge. Basically, calling get_clock will 36 # fail if Manager is not yet fully constructed (since it's 37 # a singleton). The more correct solution is to more cleanly 38 # separate the initialization code in the Manager from the 39 # initialization that actually involves interacting with 40 # other components (which may want to use the logger) 41 haizeatime = " " 42 extra = { "haizeatime" : haizeatime} 43 if sys.version_info[1] <= 4: 44 name = "[%s] %s" % (haizeatime, name) 45 return logging.Logger.makeRecord(self, name, lvl, fn, lno, msg, args, exc_info) 46 else: 47 return logging.Logger.makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func, extra)
48
49 - def status(self, msg):
50 self.log(logging.getLevelName("STATUS"), msg)
51
52 - def vdebug(self, msg):
53 # Since there is such a huge amount of vdebug messages, we check the 54 # log level manually to decide if we call the log function or not. 55 # (this actually saves quite a bit of cycles spent in logging functions 56 # that ultimately determine that the message doesn't have to printed) 57 if self.getEffectiveLevel() == LOGLEVEL_VDEBUG: 58 self.log(logging.getLevelName("VDEBUG"), msg)
59