+ 1
How to read logs?
I was trying to save some of my code's print outputs into a .log file. I wrote this: import logging logging.basicConfig(level=logging.INFO, filename="example.log", format="%(message)s") logging.INFO("a line") Then I tried to read the last log of my .log file to restart the code from that point or something like that. So: import logging logging.basicConfig(level=logging.INFO, filename="example.log", format="%(message)s") logging.INFO("a line") file = open("example.log", "r").readlines() print(file) print(file[-1]) But It prints an empty list like .log wasn't written yet or I'm not able to read .log while my code is working on It :(( Any suggestions or easier methods to do this? Thanks in Advance :))
2 Réponses
+ 1
I usually use them, i don't know why not this time XD
Anyway, thanksss :))