1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import os
21 import sys
22
23
24
25
26
28 """A 'Tracer' outputs trace messages useful for debugging."""
29
30 prefix = 'QM_THRESHOLD_'
31 """The prefix for an environment variable that indicates a
32 threshold for a particular trace category. The string following
33 the prefix gives the name of the trace category. If the
34 environment variable has no associated level, the associated level
35 is one. Otherwise, the associated level is given by the value of
36 the environment variable."""
37
58
59
60 - def Write(self, message, category, level=0):
61 """Output a trace message.
62
63 'message' -- A string giving the contents of the message. The
64 message should begin with a capital letter and end with a
65 period.
66
67 'category' -- A string indicating the category to which this
68 message belongs.
69
70 'level' -- A non-negative integer indicating the level at
71 which the message should be output.
72
73 Every category has an associated threshold. If the level of
74 the 'message' is less than the threshold, the mesage will be
75 output."""
76
77 if level < self.GetThreshold(category):
78 self.__file.write("[%s]: %s\n" % (category, message))
79 self.__file.flush()
80
81
83 """Return the current threshold for 'category'.
84
85 'category' -- A string giving a trace category.
86
87 returns -- The threshold associated with 'category'. If no
88 threshold has been set, the threshold is considered to be
89 zero."""
90
91 return self.__thresholds.get(category, 0)
92
93
95 """Set the threshold associated with 'category'.
96
97 'category' --A string giving a trace category.
98
99 'level' -- A non-negative integer indicating the threshold
100 level for 'category'."""
101
102 self.__thresholds[category] = level
103