user2023
user2023

Reputation: 478

How to add a timestamp into a logfile with Python class

How to concatenate the timestamp on a file in python3.

this is working: This does not have timestamp defined

 self.write_report(failed_users, "users_ldap_report.txt")

This is not working: I am trying to add timestamp in the file for tracking so want to use REPORT_TIME to be used.

 import time
 REPORT_TIME = time.strftime("%Y%m%d%H%M%S")
 self.write_report(failed_users, "users_ldap_report + REPORT_TIME.txt")

Note: failed_users is just a list .

Please guide.

Upvotes: 0

Views: 59

Answers (1)

Abhi
Abhi

Reputation: 1210

You can try the following code,

import time
REPORT_TIME = time.strftime("%Y%m%d%H%M%S")
self.write_report(failed_users, "users_ldap_report {}.txt".format(REPORT_TIME))

Upvotes: 1

Related Questions