46 lines · python
1# DExTer : Debugging Experience Tester2# ~~~~~~ ~ ~~ ~ ~~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-exception7"""Utility functions for producing command line warnings."""8 9from dex.utils import PrettyOutput10 11 12class Logger(object):13 def __init__(self, pretty_output: PrettyOutput):14 self.o = pretty_output15 self.error_color = self.o.red16 self.warning_color = self.o.yellow17 self.note_color = self.o.default18 self.verbosity = 119 20 def error(self, msg, enable_prefix=True, flag=None):21 if self.verbosity < 0:22 return23 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 return32 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 return41 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)46