PySnooper usage help

I decided to use a tool called pysnooper to get used to how to avoid placing print when debugging
I output the text of the log in the description, but when I open it with vim, it displays something difficult to read mixed with the color specification method seen in bash etc.
There is no particular explanation, and I don’t know how to display this, what should I do?

(GitHub - cool-RR/PySnooper: Never use print for debugging again)

in explain
If stderr is not easily accessible for you, you can redirect the output to a file:
@pysnooper.snoop(‘/my/log/file.log’)

Quoting from the “Advanced usage” page, which is linked from that Readme:

The output is colored for easy viewing by default, except on Windows. Disable colors like so:

@pysnooper.snoop(color=False)

So by adding a color=False argument, you can have it put plain text into the file without those colour codes.

For the record, the codes follow a very old (and widely implemented) standard:

But, yes, vim will not interpret that, because it’s designed to show you what the file contains (although still mainly interpreting it as text, not like a hex editor). So just ask for the plain output.

1 Like

It was one step late! I’ll post what I was going to post (because it’s a waste), and thanks for the response

From the description of snoop, a similar tool

  1. maybe it shaping by Pygments
  2. something called ANSI escape sequences (a.k.a. terminal colors) or ANSI sequences
  3. I managed to confirm that colored display is possible with cat
    It seems that snoop can output without including color information for the terminal, and pysnooper may have such a function

It’s not a direct “Python” question, so maybe it should have been posted on reddit instead of here.

Yes, Pygments is a popular tool for creating these sequences. Another is Colorama.

1 Like

Since this is a log file, I realized that the text is appended
I was able to confirm that the configuration change was applied by deleting the log once in rm
I did as below

@pysnooper.snoop(‘snoopfile.log’, color=False)
def myfunc(foo):
. foo = bar
. return

Thanks