2006-11-16 15:02:15 +00:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
"""
|
|
|
|
BitBake 'msg' implementation
|
|
|
|
|
|
|
|
Message handling infrastructure for bitbake
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2007-01-08 23:53:01 +00:00
|
|
|
# Copyright (C) 2006 Richard Purdie
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
2010-04-08 17:22:29 +00:00
|
|
|
import sys
|
2010-06-09 23:17:29 +00:00
|
|
|
import logging
|
2010-04-10 02:22:52 +00:00
|
|
|
import collections
|
2010-06-09 23:17:29 +00:00
|
|
|
from itertools import groupby
|
2010-08-11 16:47:31 +00:00
|
|
|
import warnings
|
2010-04-08 17:22:29 +00:00
|
|
|
import bb
|
|
|
|
import bb.event
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-12-10 04:38:35 +00:00
|
|
|
class BBLogFormatter(logging.Formatter):
|
|
|
|
"""Formatter which ensures that our 'plain' messages (logging.INFO + 1) are used as is"""
|
|
|
|
|
2011-01-07 23:50:17 +00:00
|
|
|
DEBUG = logging.DEBUG
|
2011-01-10 19:30:05 +00:00
|
|
|
VERBOSE = logging.INFO - 1
|
2011-01-07 23:50:17 +00:00
|
|
|
NOTE = logging.INFO
|
2011-01-10 19:30:05 +00:00
|
|
|
PLAIN = logging.INFO + 1
|
2011-01-07 23:50:17 +00:00
|
|
|
ERROR = logging.ERROR
|
|
|
|
WARNING = logging.WARNING
|
|
|
|
CRITICAL = logging.CRITICAL
|
|
|
|
|
2010-12-17 18:49:31 +00:00
|
|
|
levelnames = {
|
2011-01-07 23:50:17 +00:00
|
|
|
DEBUG : 'DEBUG',
|
2010-12-17 18:49:31 +00:00
|
|
|
PLAIN : '',
|
2011-01-07 23:50:17 +00:00
|
|
|
NOTE : 'NOTE',
|
2010-12-17 18:49:31 +00:00
|
|
|
VERBOSE: 'NOTE',
|
2011-01-07 23:50:17 +00:00
|
|
|
WARNING : 'WARNING',
|
|
|
|
ERROR : 'ERROR',
|
|
|
|
CRITICAL: 'ERROR',
|
2010-12-17 18:49:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def getLevelName(self, levelno):
|
|
|
|
try:
|
|
|
|
return self.levelnames[levelno]
|
|
|
|
except KeyError:
|
|
|
|
self.levelnames[levelno] = value = 'Level %d' % levelno
|
|
|
|
return value
|
|
|
|
|
2010-12-10 04:38:35 +00:00
|
|
|
def format(self, record):
|
2010-12-17 18:49:31 +00:00
|
|
|
record.levelname = self.getLevelName(record.levelno)
|
2010-12-10 04:38:35 +00:00
|
|
|
if record.levelno == logging.INFO + 1:
|
|
|
|
return record.getMessage()
|
|
|
|
else:
|
|
|
|
return logging.Formatter.format(self, record)
|
|
|
|
|
2010-06-09 23:17:29 +00:00
|
|
|
class Loggers(dict):
|
|
|
|
def __getitem__(self, key):
|
|
|
|
if key in self:
|
|
|
|
return dict.__getitem__(self, key)
|
|
|
|
else:
|
|
|
|
log = logging.getLogger("BitBake.%s" % domain._fields[key])
|
|
|
|
dict.__setitem__(self, key, log)
|
|
|
|
return log
|
|
|
|
|
|
|
|
class DebugLevel(dict):
|
|
|
|
def __getitem__(self, key):
|
|
|
|
if key == "default":
|
|
|
|
key = domain.Default
|
|
|
|
return get_debug_level(key)
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-04-10 02:22:52 +00:00
|
|
|
def _NamedTuple(name, fields):
|
|
|
|
Tuple = collections.namedtuple(name, " ".join(fields))
|
|
|
|
return Tuple(*range(len(fields)))
|
|
|
|
|
2010-03-24 23:56:12 +00:00
|
|
|
domain = _NamedTuple("Domain", (
|
2010-04-10 02:27:21 +00:00
|
|
|
"Default",
|
|
|
|
"Build",
|
|
|
|
"Cache",
|
|
|
|
"Collection",
|
|
|
|
"Data",
|
|
|
|
"Depends",
|
|
|
|
"Fetcher",
|
|
|
|
"Parsing",
|
|
|
|
"PersistData",
|
|
|
|
"Provider",
|
|
|
|
"RunQueue",
|
|
|
|
"TaskData",
|
|
|
|
"Util"))
|
2010-06-09 23:17:29 +00:00
|
|
|
logger = logging.getLogger("BitBake")
|
|
|
|
loggers = Loggers()
|
|
|
|
debug_level = DebugLevel()
|
2007-08-15 08:39:19 +00:00
|
|
|
|
2006-11-16 15:02:15 +00:00
|
|
|
# Message control functions
|
|
|
|
#
|
|
|
|
|
|
|
|
def set_debug_level(level):
|
2010-06-09 23:17:29 +00:00
|
|
|
for log in loggers.itervalues():
|
|
|
|
log.setLevel(logging.NOTSET)
|
|
|
|
|
|
|
|
if level:
|
|
|
|
logger.setLevel(logging.DEBUG - level + 1)
|
|
|
|
else:
|
|
|
|
logger.setLevel(logging.INFO)
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-04-10 02:34:07 +00:00
|
|
|
def get_debug_level(msgdomain = domain.Default):
|
2010-06-09 23:17:29 +00:00
|
|
|
if not msgdomain:
|
|
|
|
level = logger.getEffectiveLevel()
|
|
|
|
else:
|
|
|
|
level = loggers[msgdomain].getEffectiveLevel()
|
|
|
|
return max(0, logging.DEBUG - level + 1)
|
2010-04-10 02:34:07 +00:00
|
|
|
|
2006-11-16 15:02:15 +00:00
|
|
|
def set_verbose(level):
|
2010-06-09 23:17:29 +00:00
|
|
|
if level:
|
|
|
|
logger.setLevel(logging.INFO - 1)
|
|
|
|
else:
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
|
|
|
def set_debug_domains(domainargs):
|
|
|
|
for (domainarg, iterator) in groupby(domainargs):
|
|
|
|
for index, msgdomain in enumerate(domain._fields):
|
|
|
|
if msgdomain == domainarg:
|
|
|
|
level = len(tuple(iterator))
|
|
|
|
if level:
|
|
|
|
loggers[index].setLevel(logging.DEBUG - level + 1)
|
2010-04-10 02:22:52 +00:00
|
|
|
break
|
|
|
|
else:
|
2010-06-09 23:17:29 +00:00
|
|
|
warn(None, "Logging domain %s is not valid, ignoring" % domainarg)
|
2006-11-16 15:02:15 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Message handling functions
|
|
|
|
#
|
|
|
|
|
2010-09-04 01:49:02 +00:00
|
|
|
def debug(level, msgdomain, msg):
|
2010-08-11 16:47:31 +00:00
|
|
|
warnings.warn("bb.msg.debug will soon be deprecated in favor of the python 'logging' module",
|
|
|
|
PendingDeprecationWarning, stacklevel=2)
|
2010-06-09 23:17:29 +00:00
|
|
|
level = logging.DEBUG - (level - 1)
|
2010-04-10 02:27:21 +00:00
|
|
|
if not msgdomain:
|
2010-06-10 17:35:31 +00:00
|
|
|
logger.debug(level, msg)
|
2010-06-09 23:17:29 +00:00
|
|
|
else:
|
2010-06-10 17:35:31 +00:00
|
|
|
loggers[msgdomain].debug(level, msg)
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-09-04 01:49:02 +00:00
|
|
|
def plain(msg):
|
2010-08-11 16:47:31 +00:00
|
|
|
warnings.warn("bb.msg.plain will soon be deprecated in favor of the python 'logging' module",
|
|
|
|
PendingDeprecationWarning, stacklevel=2)
|
2010-06-10 17:35:31 +00:00
|
|
|
logger.plain(msg)
|
2010-08-11 16:47:31 +00:00
|
|
|
|
2010-09-04 01:49:02 +00:00
|
|
|
def note(level, msgdomain, msg):
|
2010-08-11 16:47:31 +00:00
|
|
|
warnings.warn("bb.msg.note will soon be deprecated in favor of the python 'logging' module",
|
|
|
|
PendingDeprecationWarning, stacklevel=2)
|
2010-06-10 17:35:31 +00:00
|
|
|
if level > 1:
|
|
|
|
if msgdomain:
|
|
|
|
logger.verbose(msg)
|
|
|
|
else:
|
|
|
|
loggers[msgdomain].verbose(msg)
|
2010-06-09 23:17:29 +00:00
|
|
|
else:
|
2010-06-10 17:35:31 +00:00
|
|
|
if msgdomain:
|
|
|
|
logger.info(msg)
|
|
|
|
else:
|
|
|
|
loggers[msgdomain].info(msg)
|
2010-09-04 01:49:02 +00:00
|
|
|
|
|
|
|
def warn(msgdomain, msg):
|
2010-08-11 16:47:31 +00:00
|
|
|
warnings.warn("bb.msg.warn will soon be deprecated in favor of the python 'logging' module",
|
|
|
|
PendingDeprecationWarning, stacklevel=2)
|
2010-06-09 23:17:29 +00:00
|
|
|
if not msgdomain:
|
|
|
|
logger.warn(msg)
|
|
|
|
else:
|
|
|
|
loggers[msgdomain].warn(msg)
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-09-04 01:49:02 +00:00
|
|
|
def error(msgdomain, msg):
|
2010-08-11 16:47:31 +00:00
|
|
|
warnings.warn("bb.msg.error will soon be deprecated in favor of the python 'logging' module",
|
|
|
|
PendingDeprecationWarning, stacklevel=2)
|
2010-06-09 23:17:29 +00:00
|
|
|
if not msgdomain:
|
|
|
|
logger.error(msg)
|
|
|
|
else:
|
|
|
|
loggers[msgdomain].error(msg)
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2010-09-04 01:49:02 +00:00
|
|
|
def fatal(msgdomain, msg):
|
2010-08-11 16:47:31 +00:00
|
|
|
warnings.warn("bb.msg.fatal will soon be deprecated in favor of raising appropriate exceptions",
|
|
|
|
PendingDeprecationWarning, stacklevel=2)
|
2010-06-09 23:17:29 +00:00
|
|
|
if not msgdomain:
|
|
|
|
logger.critical(msg)
|
|
|
|
else:
|
|
|
|
loggers[msgdomain].critical(msg)
|
2006-11-16 15:02:15 +00:00
|
|
|
sys.exit(1)
|