I am having a datetime suffix appended to my stdout for logging reasons in my application.
old_f = sys.stdout
class F:
def write(self, x):
old_f.write(x.replace("\n", " [%s]\n" % str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))))
def flush(self):
pass
sys.stdout = F()
>x = "World!"
>print("Hello " + x)
>Hello world! [2022-05-23 02:15:34]
This does the job, but I can't for the sake of it prepend the timestamp to the string, eg:
>x = "World!"
>print("Hello " + x)
>[2022-05-23 02:15:34] Hello world
I tried the regular tricks, joining, indexing etc. but the strange thing is that the time index string gets multiple times appended in between the arguments and not only in the beginning of the stdout line.