How to read logs? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 :))

4th Oct 2019, 6:45 AM
Giordano Fratti
Giordano Fratti - avatar
2 Answers
+ 1
I usually use them, i don't know why not this time XD Anyway, thanksss :))
8th Oct 2019, 3:11 PM
Giordano Fratti
Giordano Fratti - avatar