| 1 |
# DExTer : Debugging Experience Tester |
| 2 |
# ~~~~~~ ~ ~~ ~ ~~ |
| 3 |
# |
| 4 |
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 |
# See https://llvm.org/LICENSE.txt for license information. |
| 6 |
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 |
"""Utility functions for producing command line warnings.""" |
| 8 |
|
| 9 |
from dex.utils import PrettyOutput |
| 10 |
|
| 11 |
|
| 12 |
class Logger(object): |
| 13 |
def __init__(self, pretty_output: PrettyOutput): |
| 14 |
self.o = pretty_output |
| 15 |
self.error_color = self.o.red |
| 16 |
self.warning_color = self.o.yellow |
| 17 |
self.note_color = self.o.default |
| 18 |
self.verbosity = 1 |
| 19 |
|
| 20 |
def error(self, msg, enable_prefix=True, flag=None): |
| 21 |
if self.verbosity < 0: |
| 22 |
return |
| 23 |
if enable_prefix: |
| 24 |
msg = f"error: {msg}" |
| 25 |
if flag: |
| 26 |
msg = f"{msg} <y>[{flag}]</>" |
| 27 |
self.error_color("{}\n".format(msg), stream=PrettyOutput.stderr) |
| 28 |
|
| 29 |
def warning(self, msg, enable_prefix=True, flag=None): |
| 30 |
if self.verbosity < 1: |
| 31 |
return |
| 32 |
if enable_prefix: |
| 33 |
msg = f"warning: {msg}" |
| 34 |
if flag: |
| 35 |
msg = f"{msg} <y>[{flag}]</>" |
| 36 |
self.warning_color("{}\n".format(msg), stream=PrettyOutput.stderr) |
| 37 |
|
| 38 |
def note(self, msg, enable_prefix=True, flag=None): |
| 39 |
if self.verbosity < 2: |
| 40 |
return |
| 41 |
if enable_prefix: |
| 42 |
msg = f"note: {msg}" |
| 43 |
if flag: |
| 44 |
msg = f"{msg} <y>[{flag}]</>" |
| 45 |
self.note_color("{}\n".format(msg), stream=PrettyOutput.stderr) |