Merge pull request #29 from Deixx/stdout-to-file

Add logging stdout to a file in test result directory
This commit is contained in:
Katarzyna Treder 2024-11-25 09:12:04 +01:00 committed by GitHub
commit a29e65f38d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,6 +35,7 @@ def create_log(log_base_path, test_module, additional_args=None):
finally: finally:
log.begin(test_name) log.begin(test_name)
print(f"\n<LogFile>{os.path.join(log.base_dir, 'main.html')}</LogFile>") print(f"\n<LogFile>{os.path.join(log.base_dir, 'main.html')}</LogFile>")
Log.add_file_logger(log.base_dir)
if error_msg: if error_msg:
log.exception(error_msg) log.exception(error_msg)
return log return log
@ -77,6 +78,14 @@ class Log(HtmlLogManager, metaclass=Singleton):
cls.logger = logger cls.logger = logger
logger.info("Logger successfully initialized.") logger.info("Logger successfully initialized.")
@classmethod
def add_file_logger(cls, log_path):
file_handler = logging.FileHandler(os.path.join(log_path, 'stdout.log'))
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(Log.LOG_FORMAT, Log.DATE_FORMAT)
file_handler.setFormatter(formatter)
cls.logger.addHandler(file_handler)
@contextmanager @contextmanager
def step(self, message): def step(self, message):
self.step_info(message) self.step_info(message)