Project

General

Profile

root / trunk / src / haizea / core / log.py @ 641

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
from haizea.common.utils import get_clock
21
from haizea.common.constants import LOGLEVEL_VDEBUG, LOGLEVEL_STATUS
22

    
23
logging.addLevelName(LOGLEVEL_VDEBUG, "VDEBUG")
24
logging.addLevelName(LOGLEVEL_STATUS, "STATUS")
25

    
26
# Custom logger that uses our log record
27
class HaizeaLogger(logging.Logger):
28
    
29
    def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func, extra):
30
        # Modify "extra" parameter keyword
31
        haizeatime = get_clock().get_time()
32
        extra = { "haizeatime" : haizeatime}
33
        return logging.Logger.makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func, extra)
34
    
35
    def status(self, msg):
36
        self.log(logging.getLevelName("STATUS"), msg)
37

    
38
    def vdebug(self, msg):
39
        # Since there is such a huge amount of vdebug messages, we check the
40
        # log level manually to decide if we call the log function or not.
41
        # (this actually saves quite a bit of cycles spent in logging functions
42
        # that ultimately determine that the message doesn't have to printed)
43
        if self.getEffectiveLevel() == LOGLEVEL_VDEBUG:
44
            self.log(logging.getLevelName("VDEBUG"), msg)