summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/msg.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2010-06-09 16:17:29 -0700
committerRichard Purdie <rpurdie@linux.intel.com>2011-01-04 14:46:33 +0000
commit4855548ffbbb6b972f6b71d61d2b29e4758acdc7 (patch)
tree259485fe325ac4770002b4d8c53288be71bc8fc8 /bitbake/lib/bb/msg.py
parent3e57e63b2d16fa3f1ec37a904e8538e00a301fdd (diff)
downloadpoky-4855548ffbbb6b972f6b71d61d2b29e4758acdc7.tar.gz
Use the python logging module under the hood for bb.msg
(Bitbake rev: 47ca82397bc395b598c6b68b24cdee9e0d8a76d8) Signed-off-by: Chris Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/msg.py')
-rw-r--r--bitbake/lib/bb/msg.py134
1 files changed, 68 insertions, 66 deletions
diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py
index 21692d930d..254ba07a04 100644
--- a/bitbake/lib/bb/msg.py
+++ b/bitbake/lib/bb/msg.py
@@ -23,12 +23,26 @@ Message handling infrastructure for bitbake
23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 24
25import sys 25import sys
26import logging
26import collections 27import collections
28from itertools import groupby
27import bb 29import bb
28import bb.event 30import bb.event
29 31
30debug_level = collections.defaultdict(lambda: 0) 32class Loggers(dict):
31verbose = False 33 def __getitem__(self, key):
34 if key in self:
35 return dict.__getitem__(self, key)
36 else:
37 log = logging.getLogger("BitBake.%s" % domain._fields[key])
38 dict.__setitem__(self, key, log)
39 return log
40
41class DebugLevel(dict):
42 def __getitem__(self, key):
43 if key == "default":
44 key = domain.Default
45 return get_debug_level(key)
32 46
33def _NamedTuple(name, fields): 47def _NamedTuple(name, fields):
34 Tuple = collections.namedtuple(name, " ".join(fields)) 48 Tuple = collections.namedtuple(name, " ".join(fields))
@@ -49,96 +63,84 @@ domain = _NamedTuple("Domain", (
49 "TaskData", 63 "TaskData",
50 "Util")) 64 "Util"))
51 65
52 66logger = logging.getLogger("BitBake")
53class MsgBase(bb.event.Event): 67loggers = Loggers()
54 """Base class for messages""" 68debug_level = DebugLevel()
55
56 def __init__(self, msg):
57 self._message = msg
58 bb.event.Event.__init__(self)
59
60class MsgDebug(MsgBase):
61 """Debug Message"""
62
63class MsgNote(MsgBase):
64 """Note Message"""
65
66class MsgWarn(MsgBase):
67 """Warning Message"""
68
69class MsgError(MsgBase):
70 """Error Message"""
71
72class MsgFatal(MsgBase):
73 """Fatal Message"""
74
75class MsgPlain(MsgBase):
76 """General output"""
77 69
78# 70#
79# Message control functions 71# Message control functions
80# 72#
81 73
82def set_debug_level(level): 74def set_debug_level(level):
83 for d in domain: 75 for log in loggers.itervalues():
84 debug_level[d] = level 76 log.setLevel(logging.NOTSET)
85 debug_level[domain.Default] = level 77
78 if level:
79 logger.setLevel(logging.DEBUG - level + 1)
80 else:
81 logger.setLevel(logging.INFO)
86 82
87def get_debug_level(msgdomain = domain.Default): 83def get_debug_level(msgdomain = domain.Default):
88 return debug_level[msgdomain] 84 if not msgdomain:
85 level = logger.getEffectiveLevel()
86 else:
87 level = loggers[msgdomain].getEffectiveLevel()
88 return max(0, logging.DEBUG - level + 1)
89 89
90def set_verbose(level): 90def set_verbose(level):
91 verbose = level 91 if level:
92 92 logger.setLevel(logging.INFO - 1)
93def set_debug_domains(strdomains): 93 else:
94 for domainstr in strdomains: 94 logger.setLevel(logging.INFO)
95 for d in domain: 95
96 if domain._fields[d] == domainstr: 96def set_debug_domains(domainargs):
97 debug_level[d] += 1 97 for (domainarg, iterator) in groupby(domainargs):
98 for index, msgdomain in enumerate(domain._fields):
99 if msgdomain == domainarg:
100 level = len(tuple(iterator))
101 if level:
102 loggers[index].setLevel(logging.DEBUG - level + 1)
98 break 103 break
99 else: 104 else:
100 warn(None, "Logging domain %s is not valid, ignoring" % domainstr) 105 warn(None, "Logging domain %s is not valid, ignoring" % domainarg)
101 106
102# 107#
103# Message handling functions 108# Message handling functions
104# 109#
105 110
106def debug(level, msgdomain, msg, fn = None): 111def debug(level, msgdomain, msg, fn = None):
112 level = logging.DEBUG - (level - 1)
107 if not msgdomain: 113 if not msgdomain:
108 msgdomain = domain.Default 114 logger.log(level, msg)
109 115 else:
110 if debug_level[msgdomain] >= level: 116 loggers[msgdomain].log(level, msg)
111 bb.event.fire(MsgDebug(msg), None)
112 if bb.event.useStdout:
113 print('DEBUG: %s' % (msg))
114 117
118def plain(msg, fn = None):
119 logger.log(logging.INFO + 1, msg)
120
115def note(level, msgdomain, msg, fn = None): 121def note(level, msgdomain, msg, fn = None):
122 level = logging.INFO - (level - 1)
116 if not msgdomain: 123 if not msgdomain:
117 msgdomain = domain.Default 124 logger.log(level, msg)
118 125 else:
119 if level == 1 or verbose or debug_level[msgdomain] >= 1: 126 loggers[msgdomain].log(level, msg)
120 bb.event.fire(MsgNote(msg), None) 127
121 if bb.event.useStdout:
122 print('NOTE: %s' % (msg))
123
124def warn(msgdomain, msg, fn = None): 128def warn(msgdomain, msg, fn = None):
125 bb.event.fire(MsgWarn(msg), None) 129 if not msgdomain:
126 if bb.event.useStdout: 130 logger.warn(msg)
127 print('WARNING: %s' % (msg)) 131 else:
132 loggers[msgdomain].warn(msg)
128 133
129def error(msgdomain, msg, fn = None): 134def error(msgdomain, msg, fn = None):
130 bb.event.fire(MsgError(msg), None) 135 if not msgdomain:
131 if bb.event.useStdout: 136 logger.error(msg)
132 print('ERROR: %s' % (msg)) 137 else:
138 loggers[msgdomain].error(msg)
133 139
134def fatal(msgdomain, msg, fn = None): 140def fatal(msgdomain, msg, fn = None):
135 bb.event.fire(MsgFatal(msg), None) 141 if not msgdomain:
136 142 logger.critical(msg)
137 if bb.event.useStdout: 143 else:
138 print('FATAL: %s' % (msg)) 144 loggers[msgdomain].critical(msg)
139 sys.exit(1) 145 sys.exit(1)
140 146
141def plain(msg, fn = None):
142 bb.event.fire(MsgPlain(msg), None)
143 if bb.event.useStdout:
144 print(msg)