Skip to content
Advertisement

Print timestamp for logging in Python

I want to print the current timestamp, when an event succeeded or not in my python script. By only adding…

JavaScript

…. at the beginning of each line, te same date appears in every line

JavaScript

(I added time.sleep(5)in between)

My next idea was to create a function, calling the current time, but i’m failing at embedding this function to the printcommand.

File rs.py

JavaScript

File myapp.py

JavaScript

Is printing:

JavaScript

Advertisement

Answer

Before the first time you log anything do this:

JavaScript

Example on the REPL:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement