fix: logging utf-8 cannot decode

This commit is contained in:
2024-06-03 12:36:23 +08:00
parent 0e2d6fe1a2
commit 470cdab4f6

View File

@@ -76,7 +76,8 @@ class PackageInstaller():
# Set up logging configuration
logfile_path = Path(self.log_path, f"{logfile_name}.log")
logging.basicConfig(filename=logfile_path, level=logging.INFO)
logging.basicConfig(filename=logfile_path,
level=logging.INFO, encoding='utf-8')
# Return logger object
return logging.getLogger()
@@ -248,6 +249,7 @@ class PackageInstaller():
result = subprocess.run(cmd_list, timeout=timeout,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
if result.returncode != 0:
log.error('Command failed: %s', cmd_list)
log.error('stdout: %s', result.stdout.decode())
@@ -255,6 +257,8 @@ class PackageInstaller():
else:
log.info('Command succeeded: %s', cmd_list)
log.info('stdout: %s', result.stdout.decode())
except:
...
# return the command list, return code, stdout, and stderr as a tuple
return result