本文整理汇总了Python中coalib.output.printers.LogPrinter.LogPrinter类的典型用法代码示例。如果您正苦于以下问题:Python LogPrinter类的具体用法?Python LogPrinter怎么用?Python LogPrinter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LogPrinter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(
self,
log_printer: LogPrinter,
project_dir: str,
flush_cache: bool=False):
"""
Initialize FileCache.
:param log_printer: A LogPrinter object to use for logging.
:param project_dir: The root directory of the project to be used
as a key identifier.
:param flush_cache: Flush the cache and rebuild it.
"""
self.log_printer = log_printer
self.project_dir = project_dir
self.current_time = int(time.time())
cache_data = pickle_load(log_printer, project_dir, {})
last_time = -1
if "time" in cache_data:
last_time = cache_data["time"]
if not flush_cache and last_time > self.current_time:
log_printer.warn("It seems like you went back in time - your "
"system time is behind the last recorded run "
"time on this project. The cache will "
"be force flushed.")
flush_cache = True
self.data = cache_data.get("files", {})
if flush_cache:
self.flush_cache()
示例2: __init__
def __init__(self,
section: Section,
message_queue,
timeout=0):
"""
Constructs a new bear.
:param section: The section object where bear settings are
contained.
:param message_queue: The queue object for messages. Can be ``None``.
:param timeout: The time the bear is allowed to run. To set no
time limit, use 0.
:raises TypeError: Raised when ``message_queue`` is no queue.
:raises RuntimeError: Raised when bear requirements are not fulfilled.
"""
Printer.__init__(self)
LogPrinter.__init__(self, self)
if message_queue is not None and not hasattr(message_queue, "put"):
raise TypeError("message_queue has to be a Queue or None.")
self.section = section
self.message_queue = message_queue
self.timeout = timeout
self.setup_dependencies()
cp = type(self).check_prerequisites()
if cp is not True:
error_string = ("The bear " + self.name +
" does not fulfill all requirements.")
if cp is not False:
error_string += " " + cp
self.warn(error_string)
raise RuntimeError(error_string)
示例3: __init__
def __init__(self,
log_level=LOG_LEVEL.WARNING,
timestamp_format="%X"):
Printer.__init__(self)
LogPrinter.__init__(self, self, log_level, timestamp_format)
self.logs = []
示例4: __init__
def __init__(self,
section: Section,
message_queue,
timeout=0):
Printer.__init__(self)
LogPrinter.__init__(self, self)
if not hasattr(message_queue, "put") and message_queue is not None:
raise TypeError("message_queue has to be a Queue or None.")
self.section = section
self.message_queue = message_queue
self.timeout = timeout
示例5: run_coala
def run_coala(path):
"""
Run coala on the file at the given path. The config file is got using
the `find-config` option of coala.
:param path: The path of the file to analyze.
:return: The result dictionary from coala.
"""
results = {}
log_printer = LogPrinter(ConsolePrinter())
cwd = os.getcwd()
try:
os.chdir(os.path.dirname(path))
args = ["--find-config", "--limit-files", path, '-S',
'autoapply=false']
sections, local_bears, global_bears, targets = (
# Use `lambda *args: True` so that `gather_configuration` does
# nothing when it needs to request settings from user.
gather_configuration(lambda *args: True,
log_printer,
arg_list=args))
for section_name in sections:
section = sections[section_name]
if not section.is_enabled(targets):
continue
section_result = execute_section(
section=section,
global_bear_list=global_bears[section_name],
local_bear_list=local_bears[section_name],
print_results=lambda *args: True,
log_printer=log_printer)
results_for_section = []
for i in 1, 2:
for value in section_result[i].values():
for result in value:
if isinstance(result, HiddenResult):
continue
results_for_section.append(result)
results[section_name] = results_for_section
except BaseException as exception:
log_printer.log_exception(str(exception), exception)
finally:
os.chdir(cwd)
return results
示例6: test_logging
def test_logging(self):
uut = LogPrinter(timestamp_format="")
uut.logger = mock.MagicMock()
uut.log_message(self.log_message)
msg = Constants.COMPLEX_TEST_STRING
uut.logger.log.assert_called_with(logging.ERROR, msg)
uut = LogPrinter(log_level=LOG_LEVEL.DEBUG)
uut.logger = mock.MagicMock()
uut.log(LOG_LEVEL.ERROR, Constants.COMPLEX_TEST_STRING)
uut.logger.log.assert_called_with(logging.ERROR, msg)
uut.debug(Constants.COMPLEX_TEST_STRING, "d")
uut.logger.log.assert_called_with(logging.DEBUG, msg + " d")
uut.log_level = LOG_LEVEL.DEBUG
uut.log_exception("Something failed.", NotImplementedError(msg))
uut.logger.log.assert_any_call(logging.ERROR, "Something failed.")
uut.logger.log.assert_called_with(
logging.INFO,
"Exception was:\n{exception}: {msg}".format(
exception="NotImplementedError",
msg=msg))
示例7: __init__
def __init__(self, result_queue, log_queue):
Interactor.__init__(self)
LogPrinter.__init__(self)
self.result_queue = result_queue
self.log_queue = log_queue
self.set_up = False
示例8: __init__
def __init__(self, log_queue):
LogPrinter.__init__(self, self)
self.log_queue = log_queue
self.set_up = False
示例9: test_logging
def test_logging(self):
uut = LogPrinter(StringPrinter(), timestamp_format="")
uut.log_message(self.log_message, end="")
self.assertEqual(uut.printer.string, str(self.log_message))
uut = LogPrinter(StringPrinter(), log_level=LOG_LEVEL.DEBUG)
uut.log_message(self.log_message, end="")
self.assertEqual(
uut.printer.string,
"[ERROR][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING)
uut.printer.clear()
uut.log(LOG_LEVEL.ERROR,
Constants.COMPLEX_TEST_STRING,
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[ERROR][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING)
uut.printer.clear()
uut.debug(Constants.COMPLEX_TEST_STRING,
"d",
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[DEBUG][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING + " d")
uut.printer.clear()
uut.log_level = LOG_LEVEL.INFO
uut.debug(Constants.COMPLEX_TEST_STRING,
timestamp=self.timestamp,
end="")
self.assertEqual(uut.printer.string, "")
uut.printer.clear()
uut.info(Constants.COMPLEX_TEST_STRING,
"d",
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[INFO][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING + " d")
uut.log_level = LOG_LEVEL.WARNING
uut.printer.clear()
uut.debug(Constants.COMPLEX_TEST_STRING,
timestamp=self.timestamp,
end="")
self.assertEqual(uut.printer.string, "")
uut.printer.clear()
uut.warn(Constants.COMPLEX_TEST_STRING,
"d",
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[WARNING][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING + " d")
uut.printer.clear()
uut.err(Constants.COMPLEX_TEST_STRING,
"d",
timestamp=self.timestamp,
end="")
self.assertEqual(
uut.printer.string,
"[ERROR][" + self.timestamp.strftime("%X") + "] " +
Constants.COMPLEX_TEST_STRING + " d")
uut.log_level = LOG_LEVEL.DEBUG
uut.printer.clear()
uut.log_exception(
"Something failed.",
NotImplementedError(Constants.COMPLEX_TEST_STRING),
timestamp=self.timestamp)
self.assertTrue(uut.printer.string.startswith(
"[ERROR][" + self.timestamp.strftime("%X") +
"] Something failed.\n" +
"[DEBUG][" + self.timestamp.strftime("%X") +
"] Exception was:"))
uut.log_level = LOG_LEVEL.INFO
uut.printer.clear()
logged = uut.log_exception(
"Something failed.",
NotImplementedError(Constants.COMPLEX_TEST_STRING),
timestamp=self.timestamp,
end="")
self.assertTrue(uut.printer.string.startswith(
"[ERROR][" + self.timestamp.strftime("%X") +
"] Something failed."))
示例10: __init__
def __init__(self):
ColorPrinter.__init__(self)
LogPrinter.__init__(self)
示例11: test_set_state
def test_set_state(self):
uut = LogPrinter()
state = uut.__getstate__()
uut.__setstate__(state)
self.assertIs(uut.logger, logging.getLogger())
示例12: test_get_state
def test_get_state(self):
uut = LogPrinter()
self.assertNotIn('logger', uut.__getstate__())
示例13: test_log_level
def test_log_level(self):
uut = LogPrinter()
self.assertEqual(uut.log_level, logging.DEBUG)
uut.log_level = logging.INFO
self.assertEqual(uut.log_level, logging.INFO)
示例14: __init__
def __init__(self, log_level=LOG_LEVEL.WARNING, timestamp_format="%X"):
ColorPrinter.__init__(self)
LogPrinter.__init__(self, log_level=log_level, timestamp_format=timestamp_format)
示例15: __init__
def __init__(self):
LogPrinter.__init__(self, self)