aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mlog.py
diff options
context:
space:
mode:
authorJukka Laurila <jlaurila@google.com>2018-03-10 13:18:15 +0100
committerJussi Pakkanen <jpakkane@gmail.com>2018-03-10 18:04:52 +0200
commit52c50da6c7a921e1625fff26c7844af7d941afd9 (patch)
treee93c2d10aeed04b9a928f1387a469d98ef1524d8 /mesonbuild/mlog.py
parentf6fd03485e6ab95aae766649f621a9b4260ea674 (diff)
downloadmeson-52c50da6c7a921e1625fff26c7844af7d941afd9.zip
meson-52c50da6c7a921e1625fff26c7844af7d941afd9.tar.gz
meson-52c50da6c7a921e1625fff26c7844af7d941afd9.tar.bz2
Refactor: Add log.error and log.exception to reduce code duplication.
Diffstat (limited to 'mesonbuild/mlog.py')
-rw-r--r--mesonbuild/mlog.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py
index 3c34b85..347cede 100644
--- a/mesonbuild/mlog.py
+++ b/mesonbuild/mlog.py
@@ -102,19 +102,38 @@ def log(*args, **kwargs):
arr = process_markup(args, True)
force_print(*arr, **kwargs)
-def warning(*args, **kwargs):
+def _log_error(severity, *args, **kwargs):
from . import environment
-
- args = (yellow('WARNING:'),) + args
+ if severity == 'warning':
+ args = (yellow('WARNING:'),) + args
+ elif severity == 'error':
+ args = (red('ERROR:'),) + args
+ else:
+ assert False, 'Invalid severity ' + severity
if 'location' in kwargs:
location = kwargs['location']
del kwargs['location']
- location = '{}:{}:'.format(os.path.join(location.subdir, environment.build_filename), location.lineno)
- args = (location,) + args
+ location_str = '{}:{}:'.format(os.path.join(location.subdir,
+ environment.build_filename),
+ location.lineno)
+ args = (location_str,) + args
log(*args, **kwargs)
+def error(*args, **kwargs):
+ return _log_error('error', *args, **kwargs)
+
+def warning(*args, **kwargs):
+ return _log_error('warning', *args, **kwargs)
+
+def exception(e):
+ log()
+ if hasattr(e, 'file') and hasattr(e, 'lineno') and hasattr(e, 'colno'):
+ log('%s:%d:%d:' % (e.file, e.lineno, e.colno), red('ERROR: '), e)
+ else:
+ log(red('ERROR:'), e)
+
# Format a list for logging purposes as a string. It separates
# all but the last item with commas, and the last with 'and'.
def format_list(list):