Printing to the console

below is a function that takes in a message that prints the message to the console with the print statement, and also logs the message to a file by appending to it

def log(message):
    timestamp = utcTimestamp()
    print(f"{timestamp} {message}")
    try:
        with open(f"{logfile}", "a") as outfile:
            outfile.write(f"{timestamp} {message}\n")
    except Exception as err:
        print(f"{timestamp} ERROR in log(): {err}")
    return timestamp

However, a problem is that although the function is able to successfully write to a file when it is prompted, but the print statement seems not to be executed as there is not printed statements in the console. How do I solve the problem and also be able to see the print statements in the console?

never mind, problem solved

Hey @TonyCen. It’s great to hear that you’ve fixed your problem, but please provide an explanation to how you did, so that other people who have the same problem know the solution.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.