root / branches / 1.1 / src / haizea / core / log.py @ 847
1 | 632 | borja | # -------------------------------------------------------------------------- #
|
---|---|---|---|
2 | 641 | borja | # Copyright 2006-2009, University of Chicago #
|
3 | # Copyright 2008-2009, Distributed Systems Architecture Group, Universidad #
|
||
4 | 632 | borja | # 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 | 675 | borja | import sys |
21 | 632 | borja | 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 | 675 | borja | def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func=None, extra=None): |
31 | 632 | borja | # Modify "extra" parameter keyword
|
32 | 693 | borja | haizeatime = get_clock().get_time() |
33 | 675 | borja | extra = { "haizeatime" : haizeatime}
|
34 | if sys.version_info[1] <= 4: |
||
35 | name = "[%s] %s" % (haizeatime, name)
|
||
36 | return logging.Logger.makeRecord(self, name, lvl, fn, lno, msg, args, exc_info) |
||
37 | else:
|
||
38 | return logging.Logger.makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func, extra) |
||
39 | 632 | borja | |
40 | def status(self, msg): |
||
41 | self.log(logging.getLevelName("STATUS"), msg) |
||
42 | |||
43 | def vdebug(self, msg): |
||
44 | # Since there is such a huge amount of vdebug messages, we check the
|
||
45 | # log level manually to decide if we call the log function or not.
|
||
46 | # (this actually saves quite a bit of cycles spent in logging functions
|
||
47 | # that ultimately determine that the message doesn't have to printed)
|
||
48 | if self.getEffectiveLevel() == LOGLEVEL_VDEBUG: |
||
49 | self.log(logging.getLevelName("VDEBUG"), msg) |