I have a python function which prints some lines on terminal.
Here is how I execute the function:
python3 test.py
Here is some code from the file:
column1 = "|=========="
column2 = "|==============================================================="
column3 = "|==================================="
column4 = "|======================="
print("\n"+column1+column2+column3+column4+"|")
print("|SCRIPT ID |SCRIPT NAME |Start Time |RUN ID |")
print(column1+column2+column3+column4+"|")
It prints the following in terminal:
|==========|===============================================================|===================================|=======================|
|SCRIPT ID |SCRIPT NAME |Start Time | RUN ID |
|==========|===============================================================|===================================|=======================|
|1 |TEST_SCRIPT |2020-04-17 11:46:28.054074+05:30 |201 |
|==========|===============================================================|===================================|=======================|
Entering - SCRIPT
Verification Started
Verification Completed in 0 Hours 00 Min 00.000602 sec
Methods Execution Started
Methods Execution Completed
EXITING - SCRIPT
I want to maintain the output of the function in a log file. So, if I run python3 test.py, it should create a file called test.py-202004171148.log in a folder called as logs storing all the output in the file.
How can I do this?
test.py-202004171148.logwith timestamp or just random numbers?