cool-RR / PySnooper

Never use print for debugging again
MIT License
16.34k stars 951 forks source link

Question: Is there a way to delete log file (previous) or separate from new logs (between runs)? #199

Closed tassosblackg closed 3 years ago

tassosblackg commented 3 years ago

Hi, Is there a way to use the same log file again and again by separating logs between runs? Or at least delete previous logs and store new ones? Do I have to rm log file manually?

peace out,

cool-RR commented 3 years ago

Can you suggest what the ideal behavior you would want from PySnooper for your usecase?

tassosblackg commented 3 years ago

Actually both :smile: . I mean some times you need to compare logs from a function between runs and see the changes. Then after you finish your debug, and move on to the next part of code you want to debug. It's more convenient to use the same name log file instead of creating new log files, so in this case, you need to delete the old log file. :thinking:

cool-RR commented 3 years ago

I'd like you to write in a detailed and clear way what would be the ideal way that PySnooper would behave in your usecase.

tassosblackg commented 3 years ago

For example,

@pysnooper.snoop('func1.log',seperate_between_logs=True) def func (): some code here ..

The first time run creates a log file starting with : Source path:... program.py Starting var:.. file = 'input_file' ...

When I re-run the program I want the log file to look like this:

Source path:... program.py Starting var:.. file = 'input_file' ...

Second Run or New log entry

separate header-section between logs

and then the new logs: Source path:... program.py Starting var:.. file = 'input_file' ...

I mean each time I run the program I am adding new lines to the log file, is there a way to separate new entries-per-run inside the log file? Is clearer now?

tassosblackg commented 3 years ago

And if I want to delete the old log file and re-write from the first line

For example,

@pysnooper.snoop('func1.log',seperate_between_logs=False) def func (): some code here ..

and deletes the log file every time I re-run the program..

tassosblackg commented 3 years ago

So is there something like these features above, as an optional argument to pass in snoop()? or is there any other way to do similar tasks?

alexmojaki commented 3 years ago

@cool-RR I think there used to be an append option when writing to a file, did it become the only option?

cool-RR commented 3 years ago

@tassosblackg I understand. That doesn't exist, but it'll be a useful feature. If you'd like to implement it, add a global boolean to the file tracer.py that says whether PySnooper outputted anything already or not. If not, it'll output a line "Starting PySnooper output:" It'll do that always, regardless of whether you're writing to a file, or if you set overwrite=True or not.

Can you confirm that solves your problem?

@alexmojaki If you find any problems with this architecture, let us know.

alexmojaki commented 3 years ago

Ah OK, the flag I was thinking of was overwrite=True. @tassosblackg try that in your @snoop, it'll replace the previous file.

A global boolean assumes that all snoop decorators are writing to the same output, so that might be a problem.

cool-RR commented 3 years ago

Ah, then I think we better drop this feature, because if it weren't a global, I'm afraid it might write that line multiple times, and I'd rather avoid it. So @tassosblackg , sorry but I changed my mind, I wouldn't want this feature to be added.