I have tried to implement the logging function. I have successfully used datetime in my logging function but I cannot implement the function name and the line number in my code. Here is my code-
def error_log(error="Log file", filename="logs.csv"):
now = datetime.now()
logging.basicConfig(format='[%(filename)s:%(lineno)d]',
datefmt='%Y-%m-%d:%H:%M:%S',
level=logging.DEBUG)
with open(filename, 'a+') as f:
f.write(now.strftime("%m/%d/%Y, %H:%M:%S") + " ----> " + error + '\n')
Also I have attached my log file output for better understanding.
05/25/2022, 10:20:56 ----> not enough values to unpack (expected 2, got 1)
05/25/2022, 10:20:56 ----> not enough values to unpack (expected 2, got 1)
I want to implement the logging file like this--
05/25/2022, 10:20:56, function name , line number ----> not enough values to unpack (expected 2, got 1)
05/25/2022, 10:20:56, function name , line number ----> not enough values to unpack (expected 2, got 1)