Skip to content

Commit

Permalink
Adding logs for each process
Browse files Browse the repository at this point in the history
  • Loading branch information
agosh01 committed Aug 17, 2024
1 parent d3bb5a3 commit 5115fed
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions test_manager/features/steps/tck_step_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import base64
import binascii
import codecs
import datetime
import json
import os
import re
Expand Down Expand Up @@ -67,13 +68,24 @@ def create_command(context, filepath_from_root_repo: str, transport_to_send: str


def create_subprocess(command: List[str]) -> subprocess.Popen:
if sys.platform == "win32":
process = subprocess.Popen(command, shell=True)
elif sys.platform == "linux" or sys.platform == "linux2" or sys.platform == "darwin":
process = subprocess.Popen(command)
else:
print(sys.platform)
raise Exception("only handle Windows and Linux commands for now")
# Generate a unique log file name based on the current timestamp
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
log_filename = f"process_{timestamp}.log"

# Construct the full log file path
log_dir = 'logs'
os.makedirs(log_dir, exist_ok=True) # Create log directory if it doesn't exist
log_filepath = os.path.join(log_dir, log_filename)

with open(log_filepath, 'w') as logfile:
if sys.platform == "win32":
process = subprocess.Popen(command, shell=True, stdout=logfile, stderr=logfile)
elif sys.platform == "linux" or sys.platform == "linux2" or sys.platform == "darwin":
process = subprocess.Popen(command, stdout=logfile, stderr=logfile)
else:
print(sys.platform)
raise Exception("only handle Windows and Linux commands for now")

return process


Expand Down

0 comments on commit 5115fed

Please sign in to comment.