implement test.get_log_output()
Retrieve a test's own logging. The aim is to provide logging belonging to a given report fragment in the junit XML output, will be used by upcoming test.report_fragment() feature. Change-Id: Idfa0a45f3e6a18dd4fe692e81d732c70b5cffb76
This commit is contained in:
parent
e5e5df8d24
commit
12ed99628c
|
@ -264,6 +264,15 @@ class LogTarget:
|
|||
lines.insert(0, '')
|
||||
self.log_write_func('\n'.join(lines))
|
||||
|
||||
def get_mark(self):
|
||||
# implemented in FileLogTarget
|
||||
return 0
|
||||
|
||||
def get_output(self, since_mark=0):
|
||||
# implemented in FileLogTarget
|
||||
return ''
|
||||
|
||||
|
||||
def level_str(level):
|
||||
if level == L_TRACEBACK:
|
||||
return L_TRACEBACK
|
||||
|
@ -569,6 +578,21 @@ class FileLogTarget(LogTarget):
|
|||
def log_file_path(self):
|
||||
return self.path
|
||||
|
||||
def get_mark(self):
|
||||
if self.path is None:
|
||||
return 0
|
||||
# return current file length
|
||||
with open(self.path, 'r') as logfile:
|
||||
return logfile.seek(0, 2)
|
||||
|
||||
def get_output(self, since_mark=0):
|
||||
if self.path is None:
|
||||
return ''
|
||||
with open(self.path, 'r') as logfile:
|
||||
if since_mark:
|
||||
logfile.seek(since_mark)
|
||||
return logfile.read()
|
||||
|
||||
def run_logging_exceptions(func, *func_args, return_on_failure=None, **func_kwargs):
|
||||
try:
|
||||
return func(*func_args, **func_kwargs)
|
||||
|
|
|
@ -165,4 +165,22 @@ class Test(log.Origin):
|
|||
else:
|
||||
return 'test log file not available'
|
||||
|
||||
def log_file(self):
|
||||
for lt in self.log_targets:
|
||||
if isinstance(lt, log.FileLogTarget):
|
||||
return lt
|
||||
return None
|
||||
|
||||
def get_log_mark(self):
|
||||
lt = self.log_file()
|
||||
if lt is None:
|
||||
return 0
|
||||
return lt.get_mark()
|
||||
|
||||
def get_log_output(self, since_mark=0):
|
||||
lt = self.log_file()
|
||||
if lt is None:
|
||||
return ''
|
||||
return lt.get_output(since_mark)
|
||||
|
||||
# vim: expandtab tabstop=4 shiftwidth=4
|
||||
|
|
Loading…
Reference in New Issue